<a id="option1" data-id="10" data-option="21" href="#" onclick="goDoSomething(?,?);">
Click to do something
</a>
I want to get the data-id
and data-option
values inside the function goDoSomething(10, 21)
I have tried to use this
reference: this.data['id']
但它没有用。
我怎样才能做到这一点?
原文由 zkanoca 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以使用 jquery 实现这一点
$(identifier).data('id')
,javascript :如果想使用javascript标签,您可以使用
getAttribute("attributename")
,或者: