手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >ie focus bug 解决方法
ie focus bug 解决方法
摘要:如果把input.focus()放在一个setTimeout中延时执行,则就可以获得焦点。复制代码代码如下:(function(){func...

如果把input.focus()放在一个setTimeout中延时执行,则就可以获得焦点。

复制代码 代码如下:

<script type="text/javascript" >

(function(){

function get(id){

return document.getElementById(id);

}

window.onload = function(){

get('makeinput').onmousedown = function(){

var input = document.createElement('input');

input.setAttribute('type', 'text');

input.setAttribute('value', 'test1');

get('inpwrapper').appendChild(input);

input.focus();

input.select();

}

get('makeinput2').onmousedown = function(){

var input = document.createElement('input');

input.setAttribute('type', 'text');

input.setAttribute('value', 'test1');

get('inpwrapper2').appendChild(input);

setTimeout(function(){

input.focus();

input.select();

}, 0);

}

get('input').onkeypress = function(){

get('preview').innerHTML = this.value;

}

}

})();

</script>

<h1><code>setTimeout</code></h1>

<h2>1、未使用 <code>setTimeout</code></h2>

<button id="makeinput">生成 input</button>

<p id="inpwrapper"></p>

<h2>2、使用 <code>setTimeout</code></h2>

<button id="makeinput2">生成 input</button></h2>

<p id="inpwrapper2"></p>

<h2>3、另一个例子</h2>

<p><input type="text" id="input" value=""/><span id="preview"></span></p>

【ie focus bug 解决方法】相关文章:

JavaScript中length属性的使用方法

JavaScript获得url查询参数的方法

js实现点击链接后延迟3秒再跳转的方法

Javascript监视变量变化的方法

破解Session cookie的方法

Jquery解析json字符串及json数组的方法

jquery预加载图片的方法

javascript实现行拖动的方法

js实现文本框选中的方法

JavaScript中substring()方法的使用

精品推荐
分类导航