色尼玛亚洲综合影院,亚洲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 解決方法,轉載需保留來源!

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

主站蜘蛛池模板: 六枝特区| 阳泉市| 渝北区| 巴塘县| 余干县| 莱州市| 丁青县| 观塘区| 金山区| 凉城县| 阜新市| 永靖县| 鄂伦春自治旗| 西充县| 南澳县| 南乐县| 上犹县| 凤山市| 南澳县| 两当县| 黄山市| 南雄市| 建始县| 大悟县| 中牟县| 卫辉市| 禹城市| 大悟县| 西乌珠穆沁旗| 湖南省| 克东县| 巨鹿县| 双流县| 延津县| 黄龙县| 内黄县| 南岸区| 南开区| 敦化市| 库尔勒市| 宁阳县|