jqueryHandling keyboard keyupEvents
function suggest(baseUrl , data) { var wordInput = $("#userName"); wordInput.keyup(function(event) { alert(1); }//调用这个函数,弹出一个窗口,内有输入框id为userName, //第一次弹出窗口,在输入框内按一次键,弹出一次alert //关闭窗口在从新进入,在输入框内按两次键,弹出两次alert //如此递增 ,为什么啊 ,多谢 }
You are binding the keyup to the text box. If you press the key twice, of course it will play twice! What effect do you want? It is usually necessary to make a judgment and perform an operation after pressing a certain key.
The problem description is wrong
//The first time the window pops up, press the key once in the input box and it will pop up once. alert
//Close the window and re-enter, press the key twice in the input box, and alert will pop up twice.
//Close the window and re-enter, press the key twice in the input box, and alert will pop up three times
//Increase like this, why, thank you
It should be a problem of repeated binding. Is your method triggered after the pop-up window? Are there any special requirements? Change it to trigger at the beginning? In that way, it should be no problem to only bind the event once
function suggest(baseUrl , data) { var wordInput = $("#userName"); var wordInputOffset = wordInput.offset() alert(2); wordInput.keyup(function(event) { alert(1); var myEvent = event || window.event; var autoNode = $("#auto"); }} //alert(2);这个alert很正常,所以应该不是你说的问题
keyup means to lift the key. You press it and lift it once, press it again and lift it again, so that's it. This is a normal result. . If this is not your purpose, please state your desired results and we can provide you with advice.
There is a problem with the code position of the binding event. Please post the complete code. It must be bound repeatedly. Or this way
wordInput.unbind('keyup').keyup(function(event)...
is to first unbind the previously bound event and then rebind it
The above is the detailed content of Detailed introduction of jquery processing keyboard keyup event. For more information, please follow other related articles on the PHP Chinese website!