【发布时间】:2014-01-17 09:29:06
【问题描述】:
目前我正在创建一个页面。一些输入字段定义了 maxlength,对于这些字段,我希望它们可以在达到 maxlength 时将焦点移动到下一个输入。
这里我有以下代码段:
$("form input[type=text]").on('input',function ()
{
if($(this).val().length == $(this).attr('maxlength'))
{
$(this).next("input").focus();
}
});
此代码在 Chrome 和 Firefox 中运行良好,但在 IE 中无法运行。因此,我寻找解决问题的解决方案。有人建议使用 setTimeout() 方法来解决问题。 所以我修改代码如下:
setTimeout(function(){
$("form input[type=text]").on('input',function ()
{
if($(this).val().length == $(this).attr('maxlength'))
{
$(this).next("input").focus();
}
});
}, 3000);
但是在我的 IE 环境下还是不行。为了解决这个问题,我也尝试过 setInterval() 。两者都无助于解决问题。因此,我想问我如何才能实现我的目标。还是只是因为我错误地使用了 setTimeout() 方法造成的?
【问题讨论】:
-
你用的是哪个版本的IE?你可以在这里阅读msdn.microsoft.com/en-us/library/ie/gg592978.aspx
oninput事件在 IE9+ 中有效 -
很遗憾,根据需求,我正在构建的页面也需要支持 IE7 和 IE8。
标签: javascript jquery html internet-explorer focus