色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

ie focus bug 解決方法

如果把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>

JavaScript技術ie focus bug 解決方法,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 兴山县| 珠海市| 富蕴县| 荆州市| 垫江县| 遵义市| 剑阁县| 南江县| 三明市| 德惠市| 盖州市| 义马市| 府谷县| 岢岚县| 和田县| 五大连池市| 台南县| 佳木斯市| 宝鸡市| 湘西| 宜川县| 巴里| 乳山市| 密云县| 闻喜县| 邹城市| 湘阴县| 开原市| 富平县| 万年县| 嘉黎县| 鹰潭市| 商都县| 清原| 颍上县| 类乌齐县| 平谷区| 通州市| 新密市| 岳阳县| 溧阳市|