检测回车键与jquery按下

我有一个显示值的文本字段。 我想要的是,当用户在该文本字段中写入一个新的值并按下回车键时,会触发一个ajax函数来执行分页操作。 我有这样的文本字段:

<input type="text" id="page" name="page" value="<?php echo($this->pn);?> /> 

而当用户写入任何新值并按Enter时,我想要触发下面的ajax函数:

 update_ajax2({rpp:<?php echo($ this-> rpp);?>,pn:document.page.paged.value,filter:'<?php echo($ this-> filter);?>',orderby :'<?php echo($ this-> orderby);?>'});

我尝试使用keypress事件来检测if(e.which===13)但这并不能解决问题。 任何人都可以指导我?

 <input type="text" id="txt"/> $('#txt').keydown(function (e){ if(e.keyCode == 13){ alert('you pressed enter ^_^'); } }) 

在jsfiddle上 。

看看这个插件: https : //github.com/jeresig/jquery.hotkeys

使用这个,它适用于我:)

 $("#search-txt" ).on( "keydown", function(event) { if(event.which == 13) return false;//do something }); 

按键事件应该尝试

 function keyPressedTest(a) { a=(a)?a:window.event; input=(a.target)?a.target:a.srcElement; if(a.keyCode==13) { your_function() } }