javascript - Is a best common way to solve button click too fast? -
i have button.when click button, show dialog select data.
if click button fast,multi dialog show.
@ present,i have 2 way solve problem
1.use disabled
2.use settimeout , cleartimeout
have other better way solve problem?
thank much
explain:
if use disabled,after dialog close,need set button available.
@ present,i use code
util.prototype.lazytriggerevent = function(buttonid,event,callback){ var searchtrigger=null; $("#"+buttonid).bind(event,function(){ var text = $.trim($(this).val()); cleartimeout(searchtrigger); searchtrigger = settimeout(function(){ callback(text); },500); }) }; //util.lazytriggerevent("showdialgbtnid","click",function(){})
if click button trigger ajax,and have more button this,is best common way solve problem.
you can use jquery's .one()
handler limits function running once:
description: attach handler event elements. handler executed @ once per element per event type.
$('button').one('click', function() { // stuff });
or can disable button on click:
$('button').click(function() { $(this).prop('disabled', true); // stuff });
to re-enable button, can add following close modal function:
$('button').prop('disabled', false);
Comments
Post a Comment