欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

DOM-5 confirm js跳转

程序员文章站 2024-03-19 22:48:46
...

通过confirm获取

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>DOM练习</title>
</head>
<body>

    <input type="button" value="Over Check" onmouseover="MyConfirm();">

    <script>
        function MyConfirm() {
            var ret = confirm("Value Check");
            console.log(ret);
        }
    </script>

</body>
</html>

JS获取跳转网址

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>DOM练习</title>
</head>
<body>

    <input type="button" value="Over Check" onmouseover="MyConfirm();">

    <script>
        function MyConfirm() {
            var ret = confirm("Value Check");
            console.log(ret);
        }

        var lk = location.href;
//        lk即该html的link
        console.log(lk);

//        输出为:
//        file:///D:/python/oldboy/DAY13/eg04.html
//        刷新
        var lk2 = window.location.href;
        console.log('lk2:', lk2);
//        输出为
//        lk2: file:///D:/python/oldboy/DAY13/eg04.html

//        刷新
//        目前bug反复刷新
//        window.location.reload()

//        跳转至百度
        location.href = "http://www.baidu.com"
    </script>


</body>
</html>