在文本框中按下输入时运行功能 [英] Running a function when enter is pressed in a text box

查看:130
本文介绍了在文本框中按下输入时运行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的输入表格:

<input type="text" id="word" />

当用户在文本框中按Enter键时,我基本上想要执行Javascript功能。对不起,如果这是一个显而易见的问题,我找不到符合我需要的现有答案。

I basically want a Javascript function to execute when the person presses enter in the text box. I'm sorry if this is an obvious question, I couldn't find an existing answer that matched my needs.

推荐答案

< a href =http://api.jquery.com/keyup/ =nofollow> keyup() 是你的答案:

keyup() is your answer:

$('#word').keyup(function(e) {
    if(e.which == 13) {
        // Do your stuff
    }
});

e.which 返回扫描/字符按下的键的代码。 13 适用于 ENTER

e.which returns the scan/character code of the pressed key. 13 is for ENTER.

您可以找到其他代码此处

这篇关于在文本框中按下输入时运行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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