我的代码如下:
$('.summaryT').keypress(function(e){
if(e.which == 13){
callajax();
$(this).focusout();
}
});
正如您在上面的代码中看到的那样,当用户首先按下回车键时callajax()
运行(工作正常)。之后我想从.summaryT
输入框中集中注意力,我该如何实现呢?
我的代码如下:
$('.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');
}
});