jquery catch a first keypress only?

后端 未结 2 558
甜味超标
甜味超标 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.');
    });
    

提交回复
热议问题