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

首頁 > 語言 > JavaScript > 正文

ie focus bug 解決方法

2024-05-06 14:14:07
字體:
來源:轉載
供稿:網友
如果把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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 大渡口区| 东乌珠穆沁旗| 安阳县| 铁岭县| 博兴县| 鄂温| 皮山县| 本溪| 阿勒泰市| 武夷山市| 龙州县| 长葛市| 孟连| 平泉县| 天水市| 北川| 都江堰市| 武定县| 陈巴尔虎旗| 孝昌县| 刚察县| 化州市| 买车| 崇礼县| 阿荣旗| 沂水县| 财经| 稷山县| 灯塔市| 来宾市| 内乡县| 集贤县| 南丰县| 宝应县| 德惠市| 长垣县| 建湖县| 永城市| 临朐县| 新宁县| 青川县|