jquery catch a first keypress only?

后端 未结 2 559
甜味超标
甜味超标 2021-02-15 10:40

I have this code:

 $j(\"#regfname\").keypress(function () {
    alert(\'Handler for .keypress() called.\');
});

and want to execute only once..

相关标签:
2条回答
  • 2021-02-15 11:02

    You can use the jQuery one() method to only execute the event once per element.

    $j("#regfname").one("keypress", function () {
        alert('Handler for .keypress() called.');
    });
    
    0 讨论(0)
  • 2021-02-15 11:23

    You want to use the one function:

    $j('#regfname').one('keypress', function(){...});
    
    0 讨论(0)
提交回复
热议问题