gpt4 book ai didi

javascript - 使用 window.location.href 后如何将焦点设置在 div 上?

转载 作者:行者123 更新时间:2023-11-30 10:16:09 24 4
gpt4 key购买 nike

我想在使用 window.location.href 后将焦点设置在 div 上...我该怎么做?我尝试了下面的代码,但它只在 window.location.href 上起作用,它并不关注特定的 div

<script type='text/javascript'>
window.location.href="web_manage.php";

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

</script>

最佳答案

我建议:

window.location.href="web_manage.php#tab2";

但这需要接收页面(更新 window.location总是 加载一个新页面)实现一种基于其 显示该元素的方法id,散列值,出现在 URL 中。

也许使用 CSS:

#tab2:target {
display: block;
background-color: #ffa;
}

或者使用 jQuery(因为您已经在使用它):

$('#' + document.location.hash).show();

关于javascript - 使用 window.location.href 后如何将焦点设置在 div 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23620505/

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