用户按下jQuery事件在文本框中输入? [英] JQuery Event for user pressing enter in a textbox?

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

问题描述

Jquery中是否有任何事件仅在用户点击文本框中的输入按钮时触发?或者任何可以添加的插件都包含此内容?如果没有,我将如何编写一个快速插件来执行此操作?

Is there any event in Jquery that's triggered only if the user hits the enter button in a textbox? Or any plugin that can be added to include this? If not, how would I write a quick plugin that would do this?

推荐答案

您可以连接自己的自定义事件

You can wire up your own custom event

$('textarea').bind("enterKey",function(e){
   //do stuff here
});
$('textarea').keyup(function(e){
    if(e.keyCode == 13)
    {
        $(this).trigger("enterKey");
    }
});

http:// jsfiddle.net/x7HVQ/

这篇关于用户按下jQuery事件在文本框中输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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