为什么在a标签内加入javasprite再去调用函数,是固定写法吗。

来源:8-17 编程练习

慕粉3987238

2017-01-15 13:06

<!DOCTYPE html>

<html>

 <head>

  <title>浏览器对象</title>  

  <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>   

 </head>

 <body>

  <!--先编写好网页布局-->

  <h1>操作成功</h1>

<span id="second" >5</span>

  <span >秒后回到主页</span>

  <a href="javascript:back();">返回</a>

  

  

 

  <script type="text/javascript">  

    var num=document.getElementById("second").innerHTML;

   //获取显示秒数的元素,通过定时器来更改秒数。

  

    function count()

    {

        num--;

        document.getElementById("second").innerHTML=num;

        if(num==1)

        {

           window.location.assign("http://www.imooc.com");

        }

    }

    setInterval("count()",1000);

   //通过window的location和history对象来控制网页的跳转。

    function back()

    {

       window.history.back();

   }

   

 </script> 

</body>

</html>


写回答 关注

2回答

  • 麻辣与辣条
    2017-01-22 21:04:58

    楼上已经说过了,这不是固定写法。就我知道的a标签点击事件的写法就是:a href="JavaScript:method();" 或者 a href="#" onclick="method()"

  • Leoil
    2017-01-15 20:13:48

    这是在a标签有点击事件,可以有多种写法

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

468782 学习 · 22507 问题

查看课程

相似问题