我有一个可点击的按钮列表,并使用标志变量,以防止双击焦点按钮。该标志起作用,我收到预期的警报,说'你已经点击了'。问题是,下面的按钮将被视为已被点击,我会再次得到警报。我不想要这个。可点击按钮表的麻烦,需要防止双击聚焦按钮,同时保持以下可点击
var _clickFlag = true;
/* #Volunteers is a table. Each row on the table has a button that says "accept",
I pass the function the 'event' object which I use to get specific data from that table
row and send it to a database*/
$('#Volunteers').on('click','#accept', function(event){
//if clickFlag = true then the button hasn't been clicked yet.
if(_clickFlag){
//here I send some stuff to a database. I don't want to send it twice for the same
//row, which is why I need to prevent a double click
//set clickFlag to false to prevent double submission
_clickFlag = false;
}else{
//alert if the button has been clicked once already
alert("already accepted");
}
});
应该在你的代码中的错误,你可能正在使用相同的ID不止一个你纽扣。 –