javascript怎么实现按钮点击进行跳转


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>

</head>

 

<body>

    <button>点点点</button>

    <div></div>

    <script>

        var btn = document.querySelector('button')

        var div = document.querySelector('div')

        btn.addEventListener('click', function () {

            // location.href = 'http://www.baidu.com';

            var timer = 5;

            setInterval(function () {

                if (timer == 0) {

                    location.href = 'http://www.php.cn';

                } else {

                    div.innerHTML = '你还有' + timer + '秒就可以跳转了';

                    timer--

                }

            },1000)

            /*  setInterval(function(){

                 div.innerHTML = '你还有' + timer + '秒就可以跳转了'

                 timer--;

             },1000) */

        });

    </script>

</body>

 

</html>

【推荐学习:javascript高级教程

以上就是javascript怎么实现按钮点击进行跳转的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

js中eval函数有什么用

举例说明js调用php和php调用js的方法

javascript如何检查一个对象是否为空(代码示例)

javascript特权方法有什么用

javascript运行没有效果是怎么回事?

javascript中怎么将json对象转为字符串

vue组件修改根实例的数据方法(附代码)

javascript设置编码的方法有哪些

react的setsate的异步问题的分析

详解dom事件流的三个阶段

更多相关阅读请进入《javascript》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...