Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 输入按钮问题——Jquery_Javascript_Jquery_Html_Keypress - Fatal编程技术网

Javascript 输入按钮问题——Jquery

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 ==

我想在javascript中将Enter按钮(键盘上)链接到文本框,问题是有两个submit按钮链接到它。我研究了一下,意识到我可以像这样使用按键

$('#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

   }    
});