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

标签 javascript html css

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

<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/

相关文章:

javascript - 如何 "auto close"警报框

javascript - 如何在普通的旧 javascript 中访问 GWT 生成的对象?

javascript - 如何链接 .call() 函数 - 将过渡添加到 Nivo Lightbox

ios - iPad:纵向和横向模式之间的时间差

html - 证明内容 : center does not work in IE11

html - 在页眉/页脚保持静止时滚动内容

JavaScript - 如何对 div 进行排序

javascript - 在 box-shadow 上使用边框半径

html - 使用 Bootstrap 如何水平布局元素?

javascript - 在 AngularJS 中创建预览表单