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

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

主站蜘蛛池模板: 内江市| 和林格尔县| 石景山区| 北海市| 中方县| 新邵县| 卢氏县| 柳河县| 保靖县| 旺苍县| 德兴市| 开原市| 武隆县| 公主岭市| 潞西市| 田东县| 利辛县| 潼南县| 卓资县| 邹平县| 汉川市| 筠连县| 吉隆县| 扎囊县| 玉溪市| 宁乡县| 上虞市| 霍林郭勒市| 金坛市| 定日县| 汕尾市| 连云港市| 江源县| 武隆县| 孙吴县| 商水县| 荥经县| 彭阳县| 如东县| 启东市| 稷山县|