国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

ie focus bug 解決方法

2019-11-21 01:10:15
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
如果把input.focus()放在一個(gè)setTimeout中延時(shí)執(zhí)行,則就可以獲得焦點(diǎn)。
復(fù)制代碼 代碼如下:

<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、另一個(gè)例子</h2>
<p><input type="text" id="input" value=""/><span id="preview"></span></p>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 河池市| 西青区| 西宁市| 社旗县| 安多县| 五河县| 平舆县| 军事| 徐汇区| 西林县| 广西| 华池县| 鄂尔多斯市| 瓦房店市| 牡丹江市| 华阴市| 安阳县| 静乐县| 祥云县| 全椒县| 永昌县| 石楼县| 台前县| 民权县| 广水市| 齐河县| 如东县| 万盛区| 浦县| 旺苍县| 大埔区| 南投市| 周至县| 沂水县| 高尔夫| 兴化市| 枣庄市| 新源县| 澳门| 永靖县| 扎鲁特旗|