Home > Web Front-end > JS Tutorial > Detailed introduction of jquery processing keyboard keyup event

Detailed introduction of jquery processing keyboard keyup event

黄舟
Release: 2017-06-27 14:17:39
Original
1737 people have browsed it

jqueryHandling keyboard keyupEvents

function suggest(baseUrl , data) {
var wordInput = $("#userName");
wordInput.keyup(function(event) {
alert(1);
}//调用这个函数,弹出一个窗口,内有输入框id为userName,
//第一次弹出窗口,在输入框内按一次键,弹出一次alert
//关闭窗口在从新进入,在输入框内按两次键,弹出两次alert
//如此递增 ,为什么啊 ,多谢

}
Copy after login

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很正常,所以应该不是你说的问题
Copy after login

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)...
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template