To get the contents of the attribute data-id
(like in <a data-id="123">link</a>
) you have to use
(要获取属性data-id
的内容(如在<a data-id="123">link</a>
),您必须使用)
$(this).attr("data-id") // will return the string "123"
or .data()
(if you use newer jQuery >= 1.4.3)
(或.data()
(如果你使用更新的jQuery> = 1.4.3))
$(this).data("id") // will return the number 123
and the part after data-
must be lowercase, eg data-idNum
will not work, but data-idnum
will.
(并且data-
之后的部分必须是小写的,例如data-idNum
将不起作用,但data-idnum
将起作用。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…