Firefox中元素获取焦点函数focus不起作用的解决方法
2016-09-07 17:56
531 查看
文章摘抄 http://openwares.net/firefox/firefox_element_focus_not_work.html
元素获取焦点函数focus()在IE中正常Firefox中却不起作用。
js校验输入框的函数
在IE中可以正常工作,在Firefox/(windows or linux)上却无法重新获取焦点。
有两种解决办法:
1、让元素先失去焦点再获取焦点
...
feild.blur();
feild.focus();
...
这种方法在Firefox/windows上行为是正常的,但在firefox/linux平台上仍然无法获取焦点
2、定时器
...
setTimeout(function(){feild.focus();},0);
...
这种方法在firefox/windows和firefox/linux平台上都可以正常工作。
例子
元素获取焦点函数focus()在IE中正常Firefox中却不起作用。
js校验输入框的函数
function is_number(feild) { var strRegExp = /^\d+(\.\d{1,2})?$/; if (!strRegExp.test(feild.value)) { alert("请输入有效的数字,小数点后最多只能输入两位!"); feild.focus(); return false; } }
在IE中可以正常工作,在Firefox/(windows or linux)上却无法重新获取焦点。
有两种解决办法:
1、让元素先失去焦点再获取焦点
...
feild.blur();
feild.focus();
...
这种方法在Firefox/windows上行为是正常的,但在firefox/linux平台上仍然无法获取焦点
2、定时器
...
setTimeout(function(){feild.focus();},0);
...
这种方法在firefox/windows和firefox/linux平台上都可以正常工作。
例子
<script> function init(){ document.getElementById("inputId").focus(); } </script> <body onload="document.getElementById('test').focus()"> 我要获取焦点:<input type="text" name="test" id="test"> </body>
相关文章推荐
- js focus不起作用的解决方法(主要是因为dom元素是否加载完成)
- js focus不起作用的解决方法(主要是因为dom元素是否加载完成)
- 获取焦点(focus函数不起作用)
- Android ListView 中子控件无法获取焦点的解决方法(主要针对键盘操作)
- EditText和ScrollView共存,无法获取焦点,不能滚动的解决方法
- 火狐下input焦点无法重复获取问题的解决方法
- 调用focus方法使输入框获得焦点,不弹出软键盘的解决方法
- 调用focus方法使输入框获得焦点,不弹出软键盘的解决方法
- word-wrap在firefox中不起作用的解决方法
- Silverlight 4里Textbox在失去焦点之前无法获取到Text值的另类解决方法
- JavaScript教程,focus()函数示例 使控件获取与失去焦点
- [Phonegap+Sencha Touch] 移动开发10 调用focus方法使输入框获得焦点,不弹出软键盘的解决方法
- 设置元素的高度为百分比,结果不起作用的解决方法
- 解决页面中不让提交按钮获取焦点的方法,
- document.elementFromPoint在IE8下无法稳定获取当前坐标元素的解决方法
- word-wrap在firefox中不起作用的解决方法
- 【转】获取到元素的 offsetLeft 、offsetTop属性不正常的解决方法。
- jquery中focus()函数实现当对象获得焦点后自动把光标移到内容最后 //获取焦点后光标在字符串后 //其原理就是获得焦点后重新把自己复制粘帖一下 var t=$("#"+id).val()
- webdriver 获取元素焦点方法