Javascript 输入按钮问题——Jquery
我想在javascript中将Enter按钮(键盘上)链接到文本框,问题是有两个submit按钮链接到它。我研究了一下,意识到我可以像这样使用按键Javascript 输入按钮问题——Jquery,javascript,jquery,html,keypress,Javascript,Jquery,Html,Keypress,我想在javascript中将Enter按钮(键盘上)链接到文本框,问题是有两个submit按钮链接到它。我研究了一下,意识到我可以像这样使用按键 $('#searchbox input').bind('keypress', function(e) {}); 如果有一个提交按钮 有人知道如何让它为我的代码工作吗 html: 提前谢谢 试试这个 $('#searchbox input:text').bind('keypress', function(e) { if(e.which ==
$('#searchbox input').bind('keypress', function(e) {});
如果有一个提交按钮
有人知道如何让它为我的代码工作吗
html:
提前谢谢 试试这个
$('#searchbox input:text').bind('keypress', function(e) {
if(e.which == 13){//Enter pressed
//Do your stuff here
}
});
你可以做:
$('#searchbox input:text').keypress(function(e) {
e.preventDefault();//avoid submitting the form
if(e.which == 13){
//Enter pressed
}
});
看起来你的语法有问题。您是否复制正确?@primvbd如果与jquery plzz ignore中的右括号或右括号有关,在尝试编辑您的帖子后,我意识到您的语法完全错误,或者您复制并粘贴了错误的内容。这就是全部吗?我在你的网站上没有看到任何提交按钮markup@hunter输入类型=“按钮”
$('#searchbox input:text').bind('keypress', function(e) {
if(e.which == 13){//Enter pressed
//Do your stuff here
}
});
$('#searchbox input:text').keypress(function(e) {
e.preventDefault();//avoid submitting the form
if(e.which == 13){
//Enter pressed
}
});