gpt4 book ai didi

javascript - 如何使用javascript重定向到当前页面

转载 作者:行者123 更新时间:2023-11-28 10:25:33 25 4
gpt4 key购买 nike

我有我的索引页,我在其中指向一个类似这样的链接

<li onClick="CreateUser()"> <a href="#CreateUser">CreateUser</a>  </li>

单击此创建用户列表项时,我将主页内容填充为

function Create User(){ 
$("#main-content").html('Welcome to user management');
}

在我的 index.html 中,当用户第一次访问该页面时显示一些文本,我将主要内容设为

<div id="content">
<div class="outer">
<div class="inner" id="main-content">

<div class="col-lg-12">
<!--the index dashboard body goes here -->
index page content

</div>
</div><!-- /.inner -->
</div><!-- /.outer -->
</div><!-- /#content -->

我想做的是当我开机的时候刷新

localhost:/example/index.html#CreateUser

然后应该显示CreateUser函数的内容

到目前为止,我已经尝试在 index.html 页面中执行此操作

<body onLoad="checkRefresh();">

where "check Refresh()" is

function check Refresh()
{
var geturl = window.location.href;
if (geturl = 'http://localhost/example/index.html#CreateUser')
$("#main-content").html('Welcome to usermanagment');
}

但它会指示所有其他页面刷新此内容

如何做到这一点

最佳答案

我会使用 window.location.hash 和 jQuery ready

    $(document).ready(function(){
if(window.location.hash === '#CreateUser')
$("#main-content").html('Welcome to usermanagment');
});

关于javascript - 如何使用javascript重定向到当前页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23733639/

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