JS之Location常见方法(二)herf页面跳转

JS中的点击按钮herf跳转

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>location对象</title>
        <script>
        window.onload = function(){
            var bt = document.getElementById("bt");
            bt.onclick = function(){
                location.href = "https://www.baidu.com";
            }
        }
        </script>
    </head>
    <body>
        <input type="button" value="百度" id="bt" />
    </body>
</html>

 

posted @ 2022-05-07 14:01  hi123hi159  阅读(367)  评论(0)    收藏  举报