使用 JavaScript 或 jQuery 将焦点设置为动态创建的 DIV
Set focus to dynamically created DIV using JavaScript or jQuery
我创造了
Generated code :
<div id="showInfo_1" style="display: none">
--info 1
</div>
<div id="showInfo_2" style="display: none">
--info 2
</div>
jQuery : $('showInfo_2').focus();
这在 Chrome 中工作正常,但在 IE 中不行。
接下来我可以尝试什么?
Attempting to set focus to a hidden element causes an error in
Internet Explorer. Take care to only use .focus() on elements that are
visible. To run an element's focus event handlers without setting
focus to the element, use .triggerHandler( "focus" ) instead of
.focus().
我刚刚在 onclick
中添加了 return false
,它开始按照我预期的方式正常工作。
我创造了
Generated code :
<div id="showInfo_1" style="display: none">
--info 1
</div>
<div id="showInfo_2" style="display: none">
--info 2
</div>
jQuery : $('showInfo_2').focus();
这在 Chrome 中工作正常,但在 IE 中不行。
接下来我可以尝试什么?
Attempting to set focus to a hidden element causes an error in Internet Explorer. Take care to only use .focus() on elements that are visible. To run an element's focus event handlers without setting focus to the element, use .triggerHandler( "focus" ) instead of .focus().
我刚刚在 onclick
中添加了 return false
,它开始按照我预期的方式正常工作。