[英]Jquery attribute value for current element
我試圖找到被點擊元素的屬性值。 所有元素都是動態填充的。
我無法獲得屬性的值。 可能是什么問題?
<span title="cancel work" class="cancel" myid="111"><i class="fa fa-stop"></i> Stop work</span>
$(document).on('click','.cancel',(function(){
alert(this.attr("myid"));
}));
這是我收到的錯誤消息
對象不支持屬性或方法“ attr”
myid
不是有效的HTML屬性。 大多數約定都通過實現data
屬性來使用此類自定義屬性。 例如data-myid
<span title="cancel work" class="cancel" data-myid="111"><i class="fa fa-stop"></i> Stop work</span>
$(document).on('click','.cancel',(function(){
alert($(this).data("myid"));
}));
注意更改:
span
使用data-myid
data
方法獲得其價值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.