国产探花免费观看_亚洲丰满少妇自慰呻吟_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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 丹寨县| 湖北省| 屏东市| 康定县| 沈丘县| 徐汇区| 漳州市| 彝良县| 伊宁市| 南昌市| 扎赉特旗| 简阳市| 安徽省| 丰城市| 樟树市| 浮山县| 南和县| 米林县| 普格县| 资源县| 陆丰市| 伽师县| 棋牌| 交城县| 昌都县| 都匀市| 铅山县| 嘉黎县| 五原县| 北海市| 迁西县| 泌阳县| 潞城市| 久治县| 台山市| 固镇县| 鄯善县| 东乡族自治县| 收藏| 广平县| 康马县|