当按钮点击这个函数被调用防止功能的执行从双击
save_edit: function() {
this.do_save();
},
我试图禁用按钮,一旦它被点击,以防止双击。我如何在这个功能中做到这一点?
当按钮点击这个函数被调用防止功能的执行从双击
save_edit: function() {
this.do_save();
},
我试图禁用按钮,一旦它被点击,以防止双击。我如何在这个功能中做到这一点?
$("#el").click(function() {
$(this).prop('disabled',true);
// do more stuff
$(this).prop('disabled',false); // if desired
});
或者,如果你有几个按钮:
$(":button").click(function() {
$(this).prop('disabled',true);
// $(this) is a jQuery object of the button that was just clicked
str_id = $(this).attr('id'); // if you really need the ID itself
// do more stuff
});
上的dblclick在旧版本的jquery(<1:6)中,你将需要使用attr而不是prop。 – realshadow
我怎么能从这个函数中得到那个按钮的id ??????? –
这是真的;如果使用旧版本的jQuery,请使用'$(this).attr('disabled','disabled')'和$(this).attr('disabled','')'。 – Blazemonger
$("#element").dblclick(function(){
return false;
});
$("#element").click(function(){
//do stuff
});
如何我可以得到该按钮的ID来自这个功能??????? –
@TurkeshPatel:它取决于你想要禁用的内容在 – genesis
如果你不想禁用按钮,可以从调用函数的时间设定peroid停止方法。
save_edit: function() {
if(this.timer)return;
this.do_save();
this.timer = window.setTimeout(function(){}, 300); //number of ms before you want another submit to happen
},
日Thnx您的解决方案,但它不适合我 –
办法犯规机制保障的这种风格防止do_save被调用两次,想象一个异步调用调用.save_edit()的回调,它可以并行发生......你”再次“锁定” do_save开始后,你需要在它之前锁定或你有一个竞争条件。 –
$("#btn").one(function(){
//do stuff once and remove handler
});
$("#btn").dblclick(function(){
return false;
});
怎么叫那个函数? –
你的意思是禁用任何subequent点击?或禁用“双击”? –
当按钮点击从所有的联合国执行这个乐趣将执行第一.....................和禁用次级联系 –