[英]Use a preventdefault to get out of the loop after pressing Enter key
[英]Jquery focus out after pressing enter key
我的代码如下:
$('.summaryT').keypress(function(e){
if(e.which == 13){
callajax();
$(this).focusout();
}
});
正如您在上面的代码中看到的,当用户按下回车键时,首先运行callajax()
(正常工作)。 之后我想从.summaryT
输入框中集中注意力,我该如何实现这一目标?
试试这个
$('.summaryT').keypress(function(e){
if(e.which == 13){
callajax();
$(this).blur();
}
});
由于AJAX代表异步,因此您可能希望在调用成功完成后调用focusout()
。
使用jquery blur()事件
$('.summaryT').keypress(function(e){
if(e.which == 13){
callajax();
$(this).blur();
}
});
$('.selectorClass').keypress(function(e)
{
if(e.which == 13)
{
// 13 is a code to hit keyboard enter button
alert('Enter is pressed');
}
});
$('#selectorID').keypress(function(e)
{
if(e.which == 13)
{
// 13 is a code to hit keyboard enter button
alert('Enter is pressed');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.