有几个a
元素
<a class="gift-info" data-giftid="1" ...
<a class="gift-info" data-giftid="12" ...
<a class="gift-info" data-giftid="99" ...
如何获取data-giftid
属性并将值传递给函数?
$(document).ready(function() {
$("a.gift-info").click(function(){
// how to pass data-giftid value into infoHide() function?
var _id= ...
infoHide(_id);
});
});
答案 0 :(得分:0)
$(document).ready(function() {
var $ele = $("a.gift-info");
$.each($ele,function(index,element){
element.click(function(){
// how to pass data-giftid value into infoHide() function?
var _id= $(this).attr('data-giftid')
infoHide(_id);
});
}):
});