示例 2 : 跳转到另一个页面 示例 3 : Location的其他属性
reload方法刷新当前页面
<span>当前时间:</span>
<script>
var d = new Date();
document.write(d.getHours());
document.write(":");
document.write(d.getMinutes());
document.write(":");
document.write(d.getSeconds());
document.write(":");
document.write(d.getMilliseconds());
function refresh(){
location.reload();
}
</script>
<br>
<button onclick="refresh()">刷新当前页面</button>
<span>当前时间:</span> <script> var d = new Date(); document.write(d.getHours()); document.write(":"); document.write(d.getMinutes()); document.write(":"); document.write(d.getSeconds()); document.write(":"); document.write(d.getMilliseconds()); function refresh(){ location.reload(); } </script> <br> <button onclick="refresh()">刷新当前页面</button>
<script>
function jump(){
//方法1
//location="/";
//方法2
location.assign("/");
}
</script>
<br>
<button onclick="jump()">跳转到首页</button>
<script> function jump(){ //方法1 //location="/"; //方法2 location.assign("/"); } </script> <br> <button onclick="jump()">跳转到首页</button>
<script>
function p(s){
document.write(s);
document.write("<br>");
}
p("协议 location.protocol:"+location.protocol);
p("主机名 location.hostname:"+location.hostname);
p("端口号 (默认是80,没有即表示80端口)location.port:"+location.port);
p("主机加端口号 location.host: "+location.host);
p("访问的路径 location.pathname: "+location.pathname);
p("锚点 location.hash: "+location.hash);
p("参数列表 location.search: "+location.search);
</script>
<script> function p(s){ document.write(s); document.write("<br>"); } p("协议 location.protocol:"+location.protocol); p("主机名 location.hostname:"+location.hostname); p("端口号 (默认是80,没有即表示80端口)location.port:"+location.port); p("主机加端口号 location.host: "+location.host); p("访问的路径 location.pathname: "+location.pathname); p("锚点 location.hash: "+location.hash); p("参数列表 location.search: "+location.search); </script>
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
问答区域
2017-08-29
reload()
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2017-06-18
location.href和location.assign的区别
2017-06-07
一片空白
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|