我的目标是使用jquery来定位按钮的唯一ID。
例如
<button id="5412313">Remove</button>
<button id="9882813">Remove</button>
<button id="123123123">Remove</button>
<button id="214343">Remove</button>
<button id="3434343">Remove</button>
<button id="4343434">Remove</button>
Jquery的
$("#WhatshouldIputInHere?").on("click", function(){
console.log($(this));
});
答案 0 :(得分:1)
您可以尝试remove()
。
$("button").on("click", function(){
$(this).remove();
//$(this).attr('id');
});
根据您的按钮标签,我开始了解这一点。您可以使用我指定的身份做任何事情。
答案 1 :(得分:1)
您可以在处理函数中使用event
对象,代码如下:
$('button').on('click', function(event) {
alert(event.target.id);
})
答案 2 :(得分:0)
$('button').on('click',function(){
console.log($(this));
if($(this).attr('id')=='9882813'){
console.log('button with id '+$(this).attr('id')+'clicked');
}
});