在html中添加外部脚本js

第一个jswelcom.html

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>welcom~~~~~~~~~~~~~~</title>
  <script type="text/javascript" src="script07.js">
  </script>
 </head>
 <body bgcolor="#FFFFFF">
    <h2 align="center">
        <a href="nojsengine.html" id="redirect">welcom,touch me to the next page~//浏览器如果没有启用javascript就走这条连接,如果启用了则走外部脚本
        </a>
        <h3>
            hello
        </h3>
    </h2>
 </body>
</html>

 

第二个是外部脚本script07.js

window.onload = initAll;//界面加载完毕后触发initAll函数

function initAll()
{
    document.getElementById("redirect").onclick = initRedirect;//redirect元素被点击时触发initRedirect函数
}

function initRedirect()
{
    window.location = "script04.html";//设置新页面
    return false;//停止用户对点击的处理
}

 

第三个是要跳转到的script04.html

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 
  <title>our site</title>
 </head>
 <body bgcolor="#FFFFFF">
    <h1>
    Welcom to our web site,which features lots of cutting-edge javascript
    </h1>
  
 </body>
</html>

 

posted @ 2014-06-16 11:16  juandx  阅读(2623)  评论(0编辑  收藏  举报