本文介绍了无法在Firefox / Opera中设置焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用JavaScript将焦点放在表单元素上通常是非常简单的。我无法在Firefox 12.0或Opera 11中运行。
适用于其他浏览器(Chrome,IE等)和Firefox 3.6。 b
$ b
简单HTML:
< form action =>
< input type =radioid =focusID1name =sexvalue =male/>男性< br />
< input type =radioid =focusID2name =sexvalue =female/>女性< br />
< / form>
简单的Javascript:
var elem = document.getElementById(focusID2);
if(elem!= null){
elem.focus();
$ / code>
在。
解决方案
Firefox按照预期工作。问题是用jsfiddle焦点和firefox没有突出显示的焦点元素。
这不是一个问题..用户错误!
Setting focus on a form element using JavaScript is usually very straight forward.I cannot get this working in Firefox 12.0 or Opera 11.
Works in other browsers (Chrome, IE etc) and Firefox 3.6.
Simple HTML:
<form action="">
<input type="radio" id="focusID1" name="sex" value="male" /> Male<br />
<input type="radio" id="focusID2" name="sex" value="female" /> Female<br />
</form>
Simple Javascript:
var elem = document.getElementById("focusID2");
if (elem != null) {
elem.focus();
}
Try this for yourself at http://jsfiddle.net/4Ddtv/.
解决方案
Firefox was working as expected. Issue was with jsfiddle focus and firefox not highlighting the focused element.
This is not an issue.. User error!
这篇关于无法在Firefox / Opera中设置焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!