gpt4 book ai didi

javascript - jquery 专注于负载

转载 作者:数据小太阳 更新时间:2023-10-29 05:04:43 24 4
gpt4 key购买 nike

如何将焦点设置在 html 元素上?

我使用 document.getElementById('ID_HTML_wanted').focus(); 但我的 html 元素“ID_HTML_wanted”不是焦点。我使用 jquery api .focus

最佳答案

尝试将您的代码包装到此代码中,以便它在 DOM 准备就绪后执行

$(function(){
//your code
});

所以会变成

$(function(){
document.getElementById('ID_HTML_wanted').focus();
});

但是,您的元素没有 .focus() 方法,如果您想真正使用 jQuery 的方法,请使用

$(function(){
$("#ID_HTML_wanted").focus();
});

关于javascript - jquery 专注于负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7814361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com