简体   繁体   English

jQuery keydown功能不起作用

[英]jQuery keydown function not working

I need some help with making the following code work properly: 我需要一些帮助来使以下代码正常工作:

$('#entry').keydown(function(e) {
    alert(e.keyCode);
});

With this textarea field: 使用此textarea字段:

<textarea id="entry" placeholder="Type message here"></textarea>

I have checked with adding alerts outside of the brackets, and the document is loaded and works fine. 我检查了是否在方括号外添加了警报,并且该文档已加载并且可以正常工作。 I even extract a series of entries from a database right after this, with no errors. 此后,我什至从数据库中提取了一系列条目,没有错误。

What I'm looking to cook here is a textfield that when pressing Enter simply sends the .val() of the field to another function responsible for the AJAX request. 我想在这里做的是一个文本字段,当按下Enter键时,它会将字段的.val()发送到另一个负责AJAX请求的函数。 But obviously I can't get there when I cannot enter the function. 但是很明显,当我无法进入该功能时,我无法到达那里。

$(function() {
    $('#entry').on('keyup', function(e) {
        if (e.which == 13) someotherFunction(this.value);
    });
});

FIDDLE 小提琴

Try: 尝试:

$('#entry').live('keydown',function(e) {
    alert(e.keyCode);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM