jQuery仅捕获第一个按键? [英] jquery catch a first keypress only?

查看:76
本文介绍了jQuery仅捕获第一个按键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

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

,并且只想执行一次...或仅在第一次按键时执行..什么是最理想的执行方式?

and want to execute only once... or only for the first keypress ..what's the most optimal way to do it?

推荐答案

您可以使用jQuery one() 方法,每个元素仅执行一次事件.

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.');
});

这篇关于jQuery仅捕获第一个按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆