如何使用javascript重定向到当前页面
我有我的索引页,在其中我指向一个类似这样的链接如何使用javascript重定向到当前页面,javascript,html,css,Javascript,Html,Css,我有我的索引页,在其中我指向一个类似这样的链接 <li onClick="CreateUser()"> <a href="#CreateUser">CreateUser</a> </li> 在我的index.html中,当用户第一次访问页面时显示一些文本,我的主要内容如下 function Create User(){ $("#main-content").html('Welcome to user management'); } <
<li onClick="CreateUser()"> <a href="#CreateUser">CreateUser</a> </li>
在我的index.html中,当用户第一次访问页面时显示一些文本,我的主要内容如下
function Create User(){
$("#main-content").html('Welcome to user management');
}
<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 -->
然后它应该显示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');
}
其中“check Refresh()”是
函数检查刷新()
{
var geturl=window.location.href;
如果(geturl=)http://localhost/example/index.html#CreateUser')
$(“#主要内容”).html(‘欢迎使用UserManager’);
}
但它会将刷新时的所有其他页面指向此内容
如何做到这一点我将使用window.location.hash和jqueryready
$(document).ready(function(){
if(window.location.hash === '#CreateUser')
$("#main-content").html('Welcome to usermanagment');
});
我得到了答案我使用了window.location.hash和switch case
function hash()
{
//on this function clicking on icons will give the content according to tab
switch(window.location.hash) {
case "#CreateUser":
$('#CreateUser').trigger('click',CreateUser());
break;
case "#EditUser":
$('#EditUser').trigger('click',EditUser());
break;
case "#DeleteUser":
$('#DeleteUser').trigger('click',DeleteUser());
break;
default:
window.location.hash = "";
break;
}
删除
代码>在if
语句末尾。
function hash()
{
//on this function clicking on icons will give the content according to tab
switch(window.location.hash) {
case "#CreateUser":
$('#CreateUser').trigger('click',CreateUser());
break;
case "#EditUser":
$('#EditUser').trigger('click',EditUser());
break;
case "#DeleteUser":
$('#DeleteUser').trigger('click',DeleteUser());
break;
default:
window.location.hash = "";
break;
}