javascript - Running a function after a set amount of time -
I have a registration form, and I want to check the availability of the username submitted by dynamically Ajeaksa . So far, I have created an input field with an OnKeyUp event, which is reg_un_check ();
calls the function name, the current setting is the problem, which works fine, function am runs every key stroke I want to "delay" of some kind between keystrokes and function calls, so the user is typing Finish and save some bandwidth. I tried to use the SetTimeout ()
but it only delays the time between AJAX requests. I have made it yet:
Input Field:
& lt; Input type = "text" value = "username" id = "reg_un" onclick = "Reg_un_in ()" onblur = "reg_un_out ()" onkeyup = "reg_un_check ()" & gt; & Lt; Div class = "alert" id = "reg_un_alert" & gt; & Lt; / Div & gt; // div that pops out if the UN is not valid & lt; Div class = "reg_unc" id = "reg_unc_alert" & gt; & Lt; / Div & gt; / Div> Can someone recommend a different or better way to do this? Thank you.
JavaScript is a very general concept, called Dibusing, it is Lonshash library :
An easy way to create this is:
var timeoutId; Function debounceFunction () {clearTimeout (timeoutId); // No worries if there is no time-bound deadline, time = id = set timeout (delayed procedure, delay); }
is a more complicated method, but a more common way to do this is a function that provides a function and a delay, and returns a function, which is accompanied by a function That function will be executed, delay the delay before the delay and cancel the cancellation call (i.e., the Lord DeBuns function).
Function debans (CB, Delay) {var tId; Var retFunc = function () {explicit timeout (TID); SetTimeout (CB, Delay); } Return retfunc; } Function function () {// your logic here} var delayedWork = debounce (function, 150); // Now what will the delayed work call?
Hopefully I do not make it too complicated
Comments
Post a Comment