JavaScript-前进后退window.history.go(1)-后退window.history(-1)-设置地址栏上url:window.location.href=' 网址�

2022/6/13 1:20:18

本文主要是介绍JavaScript-前进后退window.history.go(1)-后退window.history(-1)-设置地址栏上url:window.location.href=' 网址�,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、前进:onclick="window.history.go(1)"

2、后退:onclick="window.history.go(-1)"

onclick="window.history.back()"

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>006-history对象.html</title>
        <!--006--007联合起来看代码  -->
    </head>
    <body>
        <a href="007.html">007页面</a>
        <input type="button" value="前进" onclick="window.history.go(1)"/>
    </body>
</html>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>007</title>
    </head>
    <body>
        007page!
        <input type="button" value="后退" onclick="window.history.back()"/>
        <input type="button" value="后退" onclick="window.history.go(-1)"/>
    </body>
</html>

 3、设置浏览器地址栏上的url:window.location.href=' 网址'

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>008设置浏览器地址栏上的url</title>
        <!--
        window.location.href="url"
        <input type="button" value="百度" onclick="goBaidu()">
        -->
    </head>
    <body>
        <script type="text/javascript">
            function goJD(){
                window.location.href='http://www.jd.com'
            }
            function goBD(){
                window.location.href='http://www.baidu.com'
            }
        </script>
        <input type="button" value="京东" onclick="goJD()" >
        <input type="button" value="百度" onclick="goBD()" >
    </body>
</html>

 



这篇关于JavaScript-前进后退window.history.go(1)-后退window.history(-1)-设置地址栏上url:window.location.href=' 网址�的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程