将焦点移至使用鼠标单击从自动完成菜单中选择值
我有下面提到的代码,它验证用户是否输入了仅在自动完成菜单中可用的数据,如果有效,那么它将移到下一个文本框。
$("#Text1").autocomplete({ source: function(req, responseFn) {
var re = $.ui.autocomplete.escapeRegex(req.term);
var textinput = new RegExp( "" +re, "i" );
var match = $.grep( crtfdesc, function(item,index){
return textinput.test(item);
});
responseFn( match );
},
change: function(event, ui){var flag;
var cval=$(this).val();
var len=crtfdesc.length;
for(var c=0;c<len;c++)
{
if(cval==crtfdesc[c]){ flag=1;$("#text2").focus();break;}
else
{ flag=2;}
}
if(flag==2){$(this).val("");}
},
select: function(event, ui){
$("#text2").focus();
}
});//Text1
但如果我使用鼠标单击选择一个值,则此代码不起作用。焦点仍然在自动完成文本框上。
I have the below mentioned code which validates whether the user had entered data which is only available in the autocomplete menu and if its valid then it will move to the next textbox.
$("#Text1").autocomplete({ source: function(req, responseFn) {
var re = $.ui.autocomplete.escapeRegex(req.term);
var textinput = new RegExp( "" +re, "i" );
var match = $.grep( crtfdesc, function(item,index){
return textinput.test(item);
});
responseFn( match );
},
change: function(event, ui){var flag;
var cval=$(this).val();
var len=crtfdesc.length;
for(var c=0;c<len;c++)
{
if(cval==crtfdesc[c]){ flag=1;$("#text2").focus();break;}
else
{ flag=2;}
}
if(flag==2){$(this).val("");}
},
select: function(event, ui){
$("#text2").focus();
}
});//Text1
but this code is not working if i select a value using mouse click. The focus remains on the autocomplete textbox.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该代码运行良好。我所做的唯一更改是从 jQuery UI Autocomplete 1.8.2 移至 jQuery UI Autocomplete 1.8.11,问题已解决。
The code is working fine. The only change that i made is i moved from jQuery UI Autocomplete 1.8.2 to jQuery UI Autocomplete 1.8.11 and the problem is solved.