admin管理员组文章数量:1278881
My setup: jQuery 1.6.2
I have this HTML
<textarea class="ment_box"> Write a ment...</textarea>
And the following Javascript
<script>
$('ment_box').keydown(function (e){
if(e.keyCode == 13){
alert('you pressed enter ^_^');
}
})
</script>
When I press the enter key in the textarea, nothing triggers
EDIT Oops, cut and paste error, I do have $
in my code and it still doesn't work, must be something else going on.
My bad, it is a user operator error, it does work. Sorry for the confusion.
My setup: jQuery 1.6.2
I have this HTML
<textarea class="ment_box"> Write a ment...</textarea>
And the following Javascript
<script>
$('.ment_box').keydown(function (e){
if(e.keyCode == 13){
alert('you pressed enter ^_^');
}
})
</script>
When I press the enter key in the textarea, nothing triggers
EDIT Oops, cut and paste error, I do have $
in my code and it still doesn't work, must be something else going on.
My bad, it is a user operator error, it does work. Sorry for the confusion.
Share Improve this question edited Aug 29, 2011 at 23:55 Bob asked Aug 29, 2011 at 23:40 BobBob 8,50418 gold badges75 silver badges110 bronze badges 1-
Guess is a type when you past code here. But
('.ment_box')
shouldn't be$('.ment_box')
? – Prusse Commented Aug 29, 2011 at 23:42
3 Answers
Reset to default 6$('.ment_box').keypress(function(event) {
// Check the keyCode and if the user pressed Enter (code = 13)
if (event.keyCode == 13) {
alert('you pressed enter ^_^');
}
});
Thats it
Check out this answer:
jQuery Event Keypress: Which key was pressed?
var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) { //Enter keycode //Do something }
For jQuery you need to use the $ to specify.
$('.ment_box').keyd
should do it.
本文标签: javascriptjQuery not detecting enter key pressed in textareaStack Overflow
版权声明:本文标题:javascript - jQuery not detecting enter key pressed in textarea - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741275432a2369700.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论