我的目标是使用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));
});
你可以试试remove()
。
$("button").on("click", function(){
$(this).remove();
//$(this).attr('id');
});
根据你的按钮标签,我开始知道这一点,你可以用你的ID做任何事情,我已经命令了。
你可以在处理程序函数中使用event
对象,代码是这样的:
$('button').on('click', function(event) {
alert(event.target.id);
})
这是上面代码的效果
$('button').on('click',function(){
console.log($(this));
if($(this).attr('id')=='9882813'){
console.log('button with id '+$(this).attr('id')+'clicked');
}
});