js focus不起作用的解决方法(主要是因为dom元素是否加载完成)

Daisy ·
更新时间:2024-09-20
· 735 次阅读

有一个文本框,id 为 d,用下面的 js 代码,想让其获得焦点。
document.getElementById("d").focus();
结果代码在 IE 中不起作用,要让 IE 中也获得焦点,得用类似如下的代码:
代码如下:
document.body.onload = function(){
document.getElementById("d").focus();
}



focus 方法 js dom

需要 登录 后方可回复, 如果你还没有账号请 注册新账号