Javascript——DOM编程

Javascript——DOM编程

 

 

基本概述

 

    文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言的标准编程接口。DOM可以以一种独立于平台和语言的方式访问和修改一个文档的内容和结构。换句话说,这是表示和处理一个HTML或XML文档的常用方法。DOM 可被 JavaScript 用来读取、改变 HTML、XHTML 以及 XML 文档。具体定义可以参考——百度百科

 

 

DOM的必要性

 

1、DOM编程重要的作用是可以让用户对网页元素进行交互操作。 

2、DOM编程可以用来做网页游戏。

3、DOM编程是ajax的重要基础。

PS:前端三大件是(HTML、CSS、JavaScript),其中JavaScript中最重要的就是DOM编程。

 

案例:

JS17_1.html

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <!DOCTYPE html>  
  2. <html>  
  3.     <head>  
  4.         <script type="text/javascript">  
  5.             function checkUser(){  
  6.                 if($("username").value == "zs" && $("password").value == "123456"){  
  7.                     // window.alert("ok");  
  8.                     return true;  
  9.                 } else {  
  10.                     // window.alert("no");  
  11.                     return false;  
  12.                 }  
  13.             }  
  14.             function $(id){  
  15.                 return document.getElementById(id);  
  16.             }  
  17.         </script>  
  18.     </head>  
  19.     <body>  
  20.         <form action="JS17_2.html">  
  21.             用户名:<input type="text" id="username" /><br/>  
  22.             密  码:<input type="text" id="password" /><br/>  
  23.             <input type="submit" onclick="return checkUser();" value="登录" />  
  24.         </form>  
  25.     </body>  
  26. </html>  

 

JS17_2.html

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
  4.         <script type="text/javascript">  
  5.             setTimeout("javascript:window.open('JS17_3.html')", 5000);  
  6.         </script>  
  7.     </head>  
  8.     <body>  
  9.         登录成功5秒后自动跳转到管理页面  
  10.     </body>  
  11. </html>  

 

JS17_3.html

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
  4.     </head>  
  5.     <body>  
  6.         OK  
  7.     </body>  
  8. </html>  

 

DOM对象

    JS把浏览器、网页文档和网页中的HTML元素都用相应的内置对象来表示,这些对象与对象间的层次关系就构成了DOM,针对网页(html,js,PHP,asp,.net)的DOM就是HTML DOM,针对XML的就是XML DOM。而现在所使用的就是HTML DOM。XML DOM要学到XML的时候才能总结。

 

HTML DOM树

    在进行HTML DOM编程的时候,会把HTML文件看做是一颗DOM树,该DOM树在内存中有着明显的层级关系,通过操作DOM树,可以动态的改变HTML页面的显示效果。

HTML文件

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.         <title>文档标题</title>  
  4.     </head>  
  5.     <body>  
  6.         <href=”#”>我的链接</a>  
  7.         <h1>我的标题</h1>  
  8.     </body>  
  9. </html>  

 

HTML DOM树

 

 

PS:从HTML DOM的角度看,任何一个HTML文件的元素都会被当做一个Node结点对象来看待。既然看做是结点对象,那么就可以使用相应对象的方法。

 

 

BOM

 

    BOM(Browser Object Model)浏览器对象模型,它规定所有的浏览器在设计时,要考虑支持BOM提出的规范,这样才能正常浏览网页。BOM和DOM关系密切,可以将BOM看做是一个指导纲领,DOM就是依照纲领实现的具体设计。BOM包括浏览器的所有对象,DOM是其中的组成部分,DOM主要是BOM中document对象的扩展。

 

 

DOM的层级关系

 

 

 

PS:DOM编程时,每个HTML元素被看成一个Node结点(对象),可以通过该文档查看具体信息:http://www.w3school.com.cn/xmldom/dom_node.asp

 

 

window对象

1、confirm()

 

    该函数会弹出一个带有确定和取消按钮的弹窗

案例:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <!--js代码是放在head标签间,但实际上也可以放在别的位置-->   
  4.     <script language="javascript">  
  5.     function test(){  
  6.        var res=window.confirm("你要删除");  
  7.        if(res){  
  8.            window.alert("删除成功");  
  9.        }  
  10.        else{  
  11.            window.alert("删除失败");  
  12.        }  
  13.     }  
  14.     </script>  
  15.     </head>  
  16.     <body>  
  17.         <input type="button" value="delete" onclick="test()">  
  18.     </body>  
  19. </html>  

 

2、setInterval()

    该函数可以根据指定的时间,循环的执行某个函数或者表达式

案例1:

[javascript] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. function sayHello(){  
  2.     window.alert("hello,world");  
  3. }  
  4. setInterval("sayHello()",1000);  

 

案例2:

在网页上显示时间

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <script>  
  4.     function showTime(){  
  5.         //在元素间的文本就是通过 对象.innerText   
  6.         document.getElementById("mytime").innerText=new Date();  
  7.     }  
  8.     setInterval("showTime()",1000);  
  9.     </script>  
  10.     </head>  
  11.     <body>  
  12.         <span id="mytime"></span>  
  13.     </body>  
  14. </html>  

 

3、clearInterval()

    该函数可以清除指定Interval

案例:

10秒时,时钟停止

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <script>  
  4.     var count=0;  
  5.     function showTime(){  
  6.         count++;  
  7.         if(count==10){  
  8.             clearInterval(time);  
  9.         }  
  10.         //在元素间的文本就是通过 对象.innerText  
  11.         document.getElementById("mytime").innerText=new Date();  
  12.     }  
  13.     var time=setInterval("showTime()",1000);  
  14.     </script>  
  15.     </head>  
  16.     <body>  
  17.         <span id="mytime"></span>  
  18.     </body>  
  19. </html>  

 

4、setTimeout() 

    该函数可以在指定的毫秒数后调用函数或计算表达式(但是只调用一次)

案例:

在打开页面后,5秒钟后弹出hello,world

[javascript] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. function sayHello(){  
  2.     window.alert("hello,world");  
  3. }  
  4. setTimeout("sayHello()",5000);  

 

5、clearTimeout()

    该函数可以清除指定Timeout

案例:

[javascript] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. function sayHello(){  
  2.     window.alert("hello,world");  
  3. }  
  4. var time=setTimeout("sayHello()",5000);  
  5. clearTimeout(time);//取消Timeout,不再显示hello,world  

 

6、moveTo()   moveBy()

   moveTo()可以移动到指定坐标,moveBy()可以移动相对当前位置的距离

PS:可以将By看做是加减操作,To是赋值操作

案例:

[javascript] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. window.moveTo(100,100); //这个是相对于屏幕左上角0,0坐标  
  2. window.moveBy(100,100);//这个是相对当前窗口的左上角0,0坐标  

 

7、resizeBy()   resizeTo()

    moveBy()是调整相对于当前的窗口大小,moveTo()是调整至某一大小

PS:可以将By看做是加减操作,To是赋值操作

案例:

[javascript] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. window.resizeTo(100,100); //把窗口的大小调整到指定的宽度100和高度100。  
  2. window.resizeBy(100,100);//把窗口再增加100,100   

8、open()

    该函数可以打开一个新窗口

案例:

 

[javascript] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. window.open("event1.html","_blank");   

 

9、opener

    该函数可以实现父窗口和子窗口通信

案例:

父窗口:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <title></title>  
  4.     <script language="javascript" type="text/javascript">  
  5.     <!--  
  6.         var newWindow;  
  7.         function test2(){  
  8.             //newWindow其实就是指向新窗口的引用  
  9.             newWindow=open("newWindow.html","_blank");  
  10.         }  
  11.         function test3(){  
  12.             newWindow.$("myspan2").innerText=$("info2").value;   
  13.         }  
  14.         function $(id){  
  15.             return document.getElementById(id);  
  16.         }  
  17.     //-->  
  18.     </script>  
  19.     </head>  
  20.     <body>  
  21.         我是父窗口  
  22.         <input type="button" value="打开新窗口" onclick="test2()"/>  
  23.         <input type="text" value="" id="info2"/>  
  24.         <input type="button" value="发送给子窗口" onclick="test3()"/><br/><br/>  
  25.         <span>接收的信息是:</span>  
  26.         <span id="myspan">信息</span>  
  27.      </body>  
  28. </html>  

 

子窗口:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <title></title>  
  4.     <script language="javascript" type="text/javascript">  
  5.     <!--   
  6.         function test2(){  
  7.             opener.$("myspan").innerText=$("info").value;  
  8.         }  
  9.         function $(id){  
  10.             return document.getElementById(id);  
  11.         }  
  12.     //-->  
  13.     </script>  
  14.     </head>  
  15.     <body>  
  16.         我是新窗口  
  17.         <input type="text" value="" id="info"/>  
  18.         <input type="button" value="发送给父窗口" onclick="test2()"/><br/><br/>  
  19.         <span>接收的信息是:</span>  
  20.         <span id="myspan2">信息</span>  
  21.     </body>  
  22. </html>  

 

PS:具体可以参考:http://www.w3school.com.cn/jsref/dom_obj_window.asp

 

10、alert() 显示带有一段消息和一个确认按钮的警告框。 在做测试的时候使用比较多!

11、prompt() 显示可提示用户输入的对话框。 

 

 

history对象

 

    其作用是记录用户访问的url,有三个函数,分别是Go,back和forward

back() 表示返回上页

go(number) 加载 history 列表中的某个具体页面。 里面有参数,如果是正整数表示下N个历史记录,如果是负整数表示上N个历史记录

forward()表示进入下页,当然需要访问过下页之后,返回之前的页面才能用这个函数

length属性,表示历史列表的url数量

 

案例:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2. <head>  
  3. <script type="text/javascript">  
  4.     function myback(){  
  5.         //window.alert('ok');  
  6.         //window.history.back();  
  7.         window.alert(history.length);  
  8.         window.history.go(-1);  
  9.     }  
  10. </script>  
  11. </head>  
  12. <body>  
  13. <h1>b.html</h1>  
  14. <input type="button" onclick="myback()" value="返回上一页面"/>  
  15. </body>  
  16. </html>  

 

location对象

    该对象包含当前url的信息

reload()方法: 重新加载当前文档,相当于刷新

案例:

[javascript] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. function myfresh(){  
  2.     window.location.reload();  // ajax局部刷新  
  3. }  
  4. //每隔十秒刷新页面  
  5. window.setInterval("myfresh()",10000);  

 

href属性:通过该属性可以指定 载入新的页面

案例:

 

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2. <body>  
  3.     <script type="text/javascript">  
  4.         document.write(location.href);  // 写入当前url  
  5.     </script>  
  6. </body>  
  7. </html>  

 

 

PS:还有一些属性方法,可以参考http://www.w3school.com.cn/jsref/dom_obj_location.asp

 

 

navigator对象

 

    该对象包括浏览器的信息

appName 属性可返回浏览器的名称。

platform 声明了运行浏览器的操作系统和(或)硬件平台。

案例:

[javascript] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. document.write(navigator.appName+" "+navigator.platform);  
  2. // 输出:Microsoft Internet Explorer Win32  

 

PS:具体可参考:http://www.w3school.com.cn/jsref/dom_obj_navigator.asp

 

 

screen对象

 

    这个对象包括用户显示屏幕的信息

 

案例:

[javascript] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. window.alert(screen.width+" "+screen.height);  
  2. if(screen.width!=1024||screen.height!=768){  
  3.     window.alert("不是这像素");  
  4. }  

 

PS:具体可参考:http://www.w3school.com.cn/jsref/dom_obj_screen.asp

 

 

event对象

 

    该对象代表事件的状态,比如事件在其中发生的元素、键盘按键的状态、鼠标的位置、鼠标按钮的状态,事件通常与函数结合使用。

注意:任何DOM对象都存在event事件。

 

绑定事件监听的三种方法

1、直接在某个HTML控件上指定

案例:

<input type="button" value="刷新页面" onclick="test()"/>

 

2、getElementById()之类的函数获取控件后,再绑定

案例:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <script language="javascript">  
  4.         function test(){  
  5.             document.write("hello,world");  
  6.         }  
  7.     </script>  
  8.     </head>  
  9.     <body>  
  10.         <input type="button" value="点击" id="but1">  
  11.         <script language="javascript">  
  12.             document.getElementById("but1").onclick=test;//这里绑定监听  
  13.        </script>  
  14.    </body>  
  15. </html>  

 

3、通过addEventListener()或者是attachEvent()绑定

PS:通过attachEvent()绑定的事件可以通过detachEvent()取消绑定

案例:

每个人只能投一次票的投票系统

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <script language="javascript">  
  4.         function test(){  
  5.             window.alert("你投票一次");  
  6.             //解除事件绑定  
  7.             document.getElementById("but1").detachEvent("onclick",test);  
  8.         }  
  9.     </script>  
  10.     </head>  
  11.     <body>  
  12.         <input type="button" value="投票" id="but1">  
  13.         <script language="javascript">  
  14.             document.getElementById("but1").attachEvent("onclick",test);  
  15.         </script>  
  16.     </body>  
  17. </html>  

 

PS:event可以参考:http://www.w3school.com.cn/jsref/dom_obj_event.asp

 

 

document对象

 

    该对象代表整个HTML文档,可以来访问页面中的所有元素,是最复杂的一个DOM对象,可以说这是DOM编程的关键所在。document对象是window对象的一个成员属性,可以通过window.document来访问,也可以直接使用document访问。

 

 

document对象常用的几个方法

1、write()

 

    这个是向文档输出文本或js代码

2、writeln()

    这个是向文档输出文本或js代码,与write不一样的地方是,writeln是换行输出

案例:

document.writeln("hello"); 

document.writeln("ok")

PS:write()和writeln()对浏览器的输出效果并没有什么区别,因为浏览器是用<br/>来表示输出的,而writeln()是在最后加一个\n。

 

3、getElementById()

    该方法获取对应id的元素。一般规定html中的id号要唯一,如果不唯一,则只取第一元素

 

4、getElementsByName()

    通过元素的名字来获取对象集合

案例:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <script language="javascript">  
  4.         function test(){  
  5.             //id不能唯一,但是name可以重复  
  6.             var hobbies=document.getElementsByName("hobby");  
  7.             window.alert(hobbies.length);  
  8.             for(var i=0;i<hobbies.length;i++){  
  9.                 //如何判断是否选择  
  10.                 if(hobbies[i].checked){  
  11.                     window.alert("选择的爱好是"+hobbies[i].value);  
  12.                 }  
  13.             }  
  14.         }  
  15.     </script>  
  16.     </head>  
  17.     <body>  
  18.          请选择你的爱好:  
  19.          <input type="checkbox" name="hobby" value="足球">足球  
  20.          <input type="checkbox" name="hobby" value="旅游" >旅游  
  21.          <input type="checkbox" name="hobby" value="音乐">音乐  
  22.          <input type="button" value="testing" onclick="test()"/>  
  23.     </body>   
  24. </html>  

 

5、getElementsByTagName()

    通过标签名来获取对象集合

案例:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <script language="javascript">  
  4.         //通过标签名来获取元素  
  5.         function test3(){  
  6.         var inputs=document.getElementsByTagName("input");  
  7.         for(var i=0;i<inputs.length;i++){  
  8.             window.alert(inputs[i].value);  
  9.         }  
  10.     }  
  11.     </script>  
  12.     </head>  
  13.     <body>  
  14.         请选择你的爱好:  
  15.         <input type="checkbox" name="hobby" value="足球">足球  
  16.         <input type="checkbox" name="hobby" value="旅游" >旅游  
  17.         <input type="checkbox" name="hobby" value="音乐">音乐  
  18.         <input type="button" value="testing" onclick="test2()"/>  
  19.         <input type="button" value="获取所有input" onclick="test3()"/>  
  20.     </body>   
  21. </html>  

 

参考文档:http://www.w3school.com.cn/jsref/dom_obj_document.asp

 

 

动态创建、添加和删除html元素(结点)

 

createElement() 方法创建新的元素节点。

appendChild() 方法向已存在的节点添加子节点。

removeChild() 方法删除指定的节点。 

parentNode 属性可返回某节点的父节点。

 

案例1:动态创建、添加html元素(结点)

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <script language="javascript">  
  4.         function test(){  
  5.             //创建元素  
  6.             //写希望创建的元素的标签名字  
  7.             var myElement=document.createElement("a");  
  8.             var myElement2=document.createElement("input");  
  9.             //给新的元素添加必要的信息  
  10.             myElement.href="http://www.baidu.com";  
  11.             myElement.innerText="连接到百度";  
  12.             myElement.id="id1";  
  13.             myElement2.type="button";  
  14.             myElement2.value="我是按钮";  
  15.             //可以指定位置  
  16.             /*myElement.style.left="200px";  
  17.             myElement.style.top="300px";  
  18.             myElement.style.position="absolute";  
  19.             //将元素添加到document.body上去  
  20.             document.body.appendChild(myElement);*/  
  21.             //将元素添加到div上去  
  22.             document.getElementById("div").appendChild(myElement);  
  23.             document.getElementById("div").appendChild(myElement2);  
  24.         }  
  25.     </script>  
  26.     </head>  
  27.     <body>  
  28.         <input type="button" onclick="test()" value="动态的创建元素">  
  29.         <div id="div" style="width:100px;height:300px;border=1px solid red"></div>  
  30.     </body>   
  31. </html>  

 

案例2:动态删除html元素(结点)

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <script>  
  4.         function test2(){  
  5.             //删除一个元素(删除一个元素的是有前提的:必须获得父元素)  
  6.             //这是第一种方法(不灵活)  
  7.             //document.getElementById("div").removeChild(document.getElementById("id1"));  
  8.             //第二种方法比较灵活(推荐)这种方法不知道父元素id也能获得父元素  
  9.             var node = document.getElementById("id1")  
  10.             node.parentNode.removeChild(document.getElementById("id1"));    
  11.         }  
  12.     </script>  
  13.     </head>  
  14.     <body>  
  15.         <input type="button" value="删除一个元素id为id1的" onclick="test2()"/>  
  16.         <div id="div" style="width:200px;height:400px; border:1px solid red;">  
  17.             <input type="button" value="button1" id=”id1”/>  
  18.         </div>  
  19.     </body>  
  20. </html>  

 

DOM加强

    在dom编程中,一个html文档会被当做 dom 树对待,dom会把所有的html元素(包括注释),映射成Node节点。于是就可以使用Node节点的属性和方法。

PS:html dom 和 xml dom 都遵循相同dom 规范的,所以有很多相同的方法和属性,因此可以去查看xml dom 的Node节点提供的方法和属性。

参考文档:http://www.w3school.com.cn/xmldom/dom_node.asp

 

案例:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
  4.     <script type="text/javascript">  
  5.         function test1(){  
  6.             //获得div1  
  7.             var div1 = $("div1");  
  8.             // 节点名,节点类型,节点值,子节点长度  
  9.             window.alert(div1.nodeName + " " + div1.nodeType + " " + div1.nodeValue + " " + div1.childNodes.length);  
  10.   
  11.             // 同一级下一个节点,同一级上一个节点,父节点  
  12.             window.alert(div1.nextSibling.nodeName + " " + div1.previousSibling.nodeName + " " + div1.parentNode.nodeName);  
  13.         }  
  14.         function $(id){  
  15.             return document.getElementById(id);  
  16.         }  
  17.     </script>  
  18. </head>  
  19. <body>      
  20.     <input type="button" value="button1" onclick="test1()" /><div id="div1">  
  21.         <div id="div2"></div>  
  22.     </div><div id="div3"></div>  
  23. </body>  
  24. </html>  

 

body对象

    body对象是document对象的一个成员属性,通过document.body来访问。使用body对象,要求文档的主体创建后才能使用,也就是说不能在文档的body体还没有创建就去访问body。

 

body常用属性:

appendChild()                        添加元素

removeChild()                        删除元素

getElementsByTagName()  通过html元素名称,得到对象数组.

bgColor                                  文档背景色

backgorund                           文档背景图

innerText                                某个元素间的文本

innerHtml                               某个元素间的html代码

onload事件                           文档加载时触发

onunload事件                       文档关闭时触发

onbeforeunload事件            文档关闭前触发

 

案例1:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <script language="javascript">  
  4.         window.alert(document.body);     //此时body访问不到,输出null  
  5.     </script>  
  6.     </head>  
  7.     <body>  
  8.     <script language="javascript">  
  9.         window.alert(document.body);  //等body创建后才能访问,此时就能输出object  
  10.     </script>  
  11.     </body>   
  12. </html>  

 

案例2:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
  4.         <script type="text/javascript">  
  5.             // 加入普通文本  
  6.             function test(){  
  7.                 $("myspan").innerText = "<a href='#'>#</a>";  
  8.             }   
  9.             // 加入HTML元素  
  10.             function test1(){  
  11.                 $("myspan").innerHTML = "<a href='#'>#</a>";  
  12.             }  
  13.             // 获取ID  
  14.             function $(id){  
  15.                 return document.getElementById(id);  
  16.             }  
  17.         </script>  
  18.     </head>  
  19.     <body>  
  20.         <span id="myspan">span</span>  
  21.         <input type="button" onclick="test()" value="button1" />  
  22.         <input type="button" onclick="test1()" value="button2" />  
  23.     </body>  
  24. </html>  

PS:innerText 和innerHTML的区别在于,innerText 浏览器会作为纯文本来解析。innerHTML 浏览器会作为html来解析。

 

案例3:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
  4.         <script type="text/javascript">  
  5.             // 定义全局变量  
  6.             directX = 2;    // x轴坐标的方向  
  7.             directY = 2;    // y轴坐标的方向  
  8.             ballX = 5;      // x轴球的坐标  
  9.             ballY = 5;      // y轴球的坐标  
  10.             // 球移动  
  11.             function ballMove(){  
  12.                 ballX += directX;  
  13.                 ballY += directY;  
  14.   
  15.                 // 修改div的left top  
  16.                 balldiv.style.top = ballY + "px";  
  17.                 balldiv.style.left = ballX + "px";  
  18.   
  19.                 // 获取边框宽度  
  20.                 var w = $("borderdiv").style.width;  
  21.                 w = w.substring(0, w.length - 2);  
  22.                 w = parseInt(w);  
  23.                 // 获取边框高度  
  24.                 var h = $("borderdiv").style.height;  
  25.                 h = h.substring(0, h.length - 2);  
  26.                 h = parseInt(h);  
  27.                 // 测试  
  28.                 // window.alert(w + " " + h);  
  29.   
  30.                 // 获取小球宽度  
  31.                 var bw = $("ball").style.width;  
  32.                 bw = bw.substring(0, bw.length - 2);  
  33.                 bw = parseInt(bw);  
  34.                 // 获取小球高度     
  35.                 var bh = $("ball").style.height;  
  36.                 bh = bh.substring(0, bh.length - 2);  
  37.                 bh = parseInt(bh);  
  38.                 // 测试  
  39.                 // window.alert(bw + " " + bh);  
  40.   
  41.                 // 判断什么时候,转变方向  
  42.                 // x方向,(offsetWidth可以返回,当前这个对象事件的宽度)  
  43.                 if(ballX + bw >= w || ballX <= 0){  
  44.                     directX = -directX;  
  45.                 }  
  46.                 // y方向,  
  47.                 if(ballY + bh >= h || ballY <= 0){  
  48.                     directY = -directY;  
  49.                 }  
  50.             }  
  51.             // 获取ID  
  52.             function $(id){  
  53.                 return document.getElementById(id);  
  54.             }  
  55.             // 设置自动调用间隔时间  
  56.             setInterval("ballMove()", 10);  
  57.         </script>  
  58.     </head>  
  59.     <body>  
  60.         <div id="borderdiv" style="border: 1px solid red; width: 500px; height: 400px;">  
  61.             <div id="balldiv" style="position: relative;">  
  62.                 <img id="ball" src="ball.png" style="width: 50px; height: 50px;" />  
  63.             </div>  
  64.         </div>  
  65.     </body>  
  66. </html>  

 

案例4:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
  4.         <script type="text/javascript">  
  5.             // 是否可移动  
  6.             var moveable = false;  
  7.             // 开始拖拽  
  8.             function startDrag(){  
  9.                 // 设置为可移动  
  10.                 moveable = true;  
  11.             }  
  12.   
  13.             // 拖拽  
  14.             function drag(event){  
  15.                 // 如果可移动  
  16.                 if(moveable){  
  17.                     // 获取鼠标坐标  
  18.                     var cx = event.clientX;  
  19.                     var cy = event.clientY;  
  20.   
  21.                     // 获取title宽度  
  22.                     var w = $("title").style.width;  
  23.                     w = w.substring(0, w.length - 2);  
  24.                     w = parseInt(w);  
  25.                     // 获取title高度  
  26.                     var h = $("title").style.height;  
  27.                     h = h.substring(0, h.length - 2);  
  28.                     h = parseInt(h);  
  29.   
  30.                     // 设置窗口坐标  
  31.                     $("div1").style.top = cy - h/2 + "px";  
  32.                     $("div1").style.left = cx - w/2 + "px";  
  33.                 }  
  34.             }  
  35.   
  36.             // 拖拽结束  
  37.             function stopDrag(){  
  38.                 // 设置为不可移动  
  39.                 moveable = false;  
  40.             }  
  41.   
  42.             // 获取ID  
  43.             function $(id){  
  44.                 return document.getElementById(id);  
  45.             }  
  46.         </script>  
  47.     </head>  
  48.     <body onmousemove="drag(event)">  
  49.         <div id="div1" style="position: absolute; width: 200px; height: 200px; background-color: #99CCFF; z-index: 200; top: 100px; left: 154px;">  
  50.         <div id="title" onmousedown="startDrag()"  onmouseup="stopDrag()" style="width: 195px; height: 20px; background-color: #330033; top: 0px; left: 0px; z-index: 200; position: absolute; font-size: 9pt; color: #FFFFFF; pading-top: 5px; padding-left: 5px; cursor: hand">浮动窗口</div>  
  51.         </div>  
  52.     </body>  
  53. </html>  

 

style对象

    style对象不是针对某一个html元素,而是对所有的html元素而言的,也就是说,我们可以通过document.getElementById(“id”).style.property=“值”,来控制网页文档的任何一个元素(对象)的样式。

参考文档:http://www.w3school.com.cn/jsref/dom_obj_style.asp

案例:

JS23.html

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <!DOCTYPE html>  
  2. <html>  
  3.   <head>  
  4.     <title>HTML15.html</title>  
  5.     <meta http-equiv="content-type" content="text/html; charset=UTF-8">  
  6.     <link rel="stylesheet" type="text/css" href="JS23.css" />  
  7.     <script type="text/javascript" src="JS23.js"></script>  
  8.   </head>  
  9.   <body>  
  10.      <!-- 首部  -->  
  11.      <div class="head">  
  12.         <div class="login">登录表单</div>  
  13.         <div class="setpage">设为首页</div>  
  14.         <div class="seta">设置超链接</div>  
  15.      </div>  
  16.      <!-- 导航部分 -->  
  17.      <div class="nav">  
  18.          <img alt="logo" src="logo.png" />  
  19.          <div>导航条</div>  
  20.      </div>  
  21.      <!-- 广告部分-->  
  22.      <div class="ad">  
  23.       <!-- 这里是仿搜狐首页修改部分 -->  
  24.       <!-- 做一个动态切换的标签 -->  
  25.         <div class="ad1">  
  26.           <div class="ad1_navi">  
  27.             <ul>  
  28.               <li onmouseover="change('zs', this)" onmouseout="change2(this)">招生</li>  
  29.               <li onmouseover="change('rz', this)" onmouseout="change2(this)">热招</li>  
  30.               <li onmouseover="change('cg', this)" onmouseout="change2(this)">出国</li>  
  31.             </ul>  
  32.           </div>  
  33.           <div id="zs" class="zs" >  
  34.           <ul>  
  35.             <li><href="#">招生招生招生招生</a></li>  
  36.             <li><href="#">招生招生招生招生</a></li>  
  37.             <li><href="#">招生招生招生招生</a></li>  
  38.             <li><href="#">招生招生招生招生</a></li>  
  39.             <li><href="#">招生招生招生招生</a></li>  
  40.             <li><href="#">招生招生招生招生</a></li>  
  41.             <li><href="#">招生招生招生招生</a></li>  
  42.             <li><href="#">招生招生招生招生</a></li>  
  43.           </ul>  
  44.         </div>  
  45.         <div id="rz" class="rz">  
  46.           <ul>  
  47.             <li><href="#">热招热招热招热招</a></li>  
  48.             <li><href="#">热招热招热招热招</a></li>  
  49.             <li><href="#">热招热招热招热招</a></li>  
  50.             <li><href="#">热招热招热招热招</a></li>  
  51.             <li><href="#">热招热招热招热招</a></li>  
  52.             <li><href="#">热招热招热招热招</a></li>  
  53.             <li><href="#">热招热招热招热招</a></li>  
  54.             <li><href="#">热招热招热招热招</a></li>  
  55.           </ul>  
  56.         </div>  
  57.         <div id="cg" class="cg">  
  58.           <ul>  
  59.             <li><href="#">出国出国出国出国</a></li>  
  60.             <li><href="#">出国出国出国出国</a></li>  
  61.             <li><href="#">出国出国出国出国</a></li>  
  62.             <li><href="#">出国出国出国出国</a></li>  
  63.             <li><href="#">出国出国出国出国</a></li>  
  64.             <li><href="#">出国出国出国出国</a></li>  
  65.             <li><href="#">出国出国出国出国</a></li>  
  66.             <li><href="#">出国出国出国出国</a></li>  
  67.           </ul>  
  68.         </div>  
  69.       </div>  
  70.         <div class="ad2">广告</div>  
  71.         <div class="ad3">房地产广告</div>  
  72.         <div class="ad4">  
  73.             <img alt="ad" src="ad2.png" />  
  74.         </div>  
  75.      </div>  
  76.   </body>  
  77. </html>  

 

JS23.css

[css] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. @CHARSET "UTF-8";  
  2.   
  3. body {  
  4.     margin: 0px auto;  
  5.     padding: 0px;  
  6.     width: 1000px;  
  7.     border: 1px solid red;  
  8. }  
  9.   
  10. /* 首部 */  
  11. .head{  
  12.     margin: 0px;  
  13.     padding: 0px;  
  14.     border: 1px solid blue;  
  15.     width: 1000px;  
  16.     height: 25px;  
  17.     margin-bottom: 5px;  
  18. }  
  19.   
  20. .login {  
  21.     width: 500px;  
  22.     margin-right: 5px;  
  23.     margin-left: 5px;  
  24. }  
  25.   
  26. .setpage {  
  27.     width: 200px;  
  28.     margin-right: 5px;  
  29. }  
  30.   
  31. .seta {  
  32.     width: 280px;  
  33. }  
  34.   
  35. .login,.setpage,.seta {  
  36.     float: left;  
  37.     height: 25px;  
  38.     background-color: silver;  
  39. }  
  40.   
  41.   
  42. /* 导航条部分 */  
  43. .nav {  
  44.     border: 1px solid red;  
  45.     width: 1000px;  
  46.     height: 67px;  
  47.     margin-bottom: 10px;  
  48. }  
  49.   
  50. .nav img {  
  51.     width: 140px;  
  52.     margin-right: 5px;  
  53. }  
  54.   
  55. .nav div {  
  56.     background-color: aqua;  
  57.     width: 855px;  
  58. }  
  59.   
  60. .nav img,.nav div {  
  61.     float: left;  
  62.     height: 67px;  
  63. }  
  64.   
  65. /* 广告部分 */  
  66. .ad {  
  67.     margin-bottom: 10px;  
  68.     border: 1px solid red;  
  69.     width: 1000px;  
  70.     height: 186px;  
  71. }  
  72.   
  73. .ad1 {  
  74.     /*background-color: orange;*/  
  75.     width: 140px;  
  76. }  
  77.   
  78. /* 广告导航条 */  
  79. .ad1_navi{  
  80.     width: 20px;  
  81.     height: 186px;  
  82.     /*background-color: green;*/  
  83.     float: left;  
  84.     font-size: 12px;  
  85. }  
  86.   
  87. .ad1_navi ul{  
  88.     padding: 0px;  
  89.     margin: 0px;  
  90.     float: left;  
  91. }  
  92.   
  93. .ad1_navi ul li{  
  94.     float: left;  
  95.     list-style-type: none;  
  96.     width: 20px;  
  97.     height: 53px;  
  98.     margin-top: 5px;  
  99.     text-align: center;  
  100.     background-color: silver;  
  101.     padding-top: 2px;  
  102. }  
  103.   
  104. .zs,.rz,.cg{  
  105.     width: 110px;  
  106.     height: 186px;  
  107.     /*background-color: pink;*/  
  108.     float: left;  
  109.     font-size: 12px;  
  110.     margin-left: 5px;  
  111. }  
  112.   
  113. .zs ul,.rz ul,.cg ul{  
  114.     padding: 0px;  
  115.     margin: 0px;  
  116.     float: left;  
  117.     margin-left: 5px;  
  118. }  
  119.   
  120. .zs ul li,.rz ul li,.cg ul li{  
  121.     list-style-type: none;  
  122.     float: left;  
  123.     line-height: 23px;  
  124. }  
  125.   
  126. .rz,.cg{  
  127.     display: none;  
  128. }  
  129.   
  130. .ad2 {  
  131.     background-color: aqua;  
  132.     width: 500px;  
  133. }  
  134.   
  135. .ad3 {  
  136.     background-color: aqua;  
  137.     width: 175px;  
  138.       
  139. }  
  140.   
  141. .ad4 {  
  142. }  
  143.   
  144. .ad1,.ad2,.ad3,.ad4 {  
  145.     float: left;  
  146.     height: 186px;  
  147.     margin-right: 5px;  
  148. }  

 

JS23.js

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. function change(val, obj){  
  2.     // window.alert("ok");  
  3.     obj.style.backgroundColor = "#FFC12D";  
  4.     if(val == "zs") {  
  5.         zs.style.display = "block";  
  6.         rz.style.display = "none";  
  7.         cg.style.display = "none";  
  8.     } else if(val == "rz") {  
  9.         rz.style.display = "block";  
  10.         zs.style.display = "none";  
  11.         cg.style.display = "none";  
  12.     } else if(val == "cg") {  
  13.         cg.style.display = "block";  
  14.         zs.style.display = "none";  
  15.         rz.style.display = "none";  
  16.     }  
  17. }  
  18.   
  19. function change2(obj){  
  20.     // window.alert("ok");  
  21.     obj.style.backgroundColor = "silver";  
  22. }  

 

PS:display 和 visiability 的区别

    两个属性都可以用于设置某个区域或者控件,显示不显示, display 设置 none; 它不显示同时让出自己占用的空间,visiability 这个属性设置成hidden 就不显示, 但是它还是占据这个空间.

 

 

forms对象集合和form对象

 

    forms 集合可返回对文档中所有 Form 对象的引用,form对象代表一个HTML表单。 

forms对象集合常用的函数和属性

length : 返回大小

item(index) : 指定取出forms对象集合的第几个form对象

说明:当访问某个表单的某个元素的时候,可以

    document . forms[第几个表单] . 元素的名字

    document . forms.item(第几个表单). 元素的名字

 

案例:

//如何取得所有表单

var forms = document.forms;

//window.alert(forms.length);

//可以通过forms访问指定表单

//window.alert(forms[0].username.value); 两者等价

window.alert(forms.item(0).username.value);

 

参考文档:http://www.w3school.com.cn/jsref/coll_doc_forms.asp

 

 

案例:表单验证综合案例

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
  4.         <script type="text/javascript">  
  5.             // 检查用户的信息是否合法  
  6.             function checkInfo(){  
  7.                 // 判断账号是否合法  
  8.                 if(document.forms[0].username.value.length 4 || document.forms[0].username.value.length > 16){  
  9.                     window.alert("用户名应在4-16位之间");  
  10.                     return false;  
  11.                 }    
  12.                 // 判断密码是否合法  
  13.                 if(document.forms[0].password1.value.length 6 || document.forms[0].username.value.length > 16){  
  14.                     window.alert("密码应该大于6位");  
  15.                     return false;  
  16.                 }  
  17.                 if(document.forms[0].password1.value != document.forms[0].password2.value){  
  18.                     window.alert("两次密码输入不一致");  
  19.                     return false;  
  20.                 }  
  21.             }  
  22.         </script>  
  23.     </head>  
  24.     <body>  
  25.         <h1 align="center">用户注册</h1>  
  26.         <form action="" method="get">  
  27.             <table border="1px" style="text-align: center;" align="center">  
  28.                 <tr>  
  29.                     <td>用户名:</td>  
  30.                     <td><input type="text" name="username"/></td>  
  31.                 </tr>  
  32.                 <tr>  
  33.                     <td>密码:</td>  
  34.                     <td><input type="password" name="password1"/></td>  
  35.                 </tr>  
  36.                 <tr>  
  37.                     <td>确认密码:</td>  
  38.                     <td><input type="password" name="password2"/></td>  
  39.                 </tr>  
  40.                 <tr>  
  41.                     <td>年龄:</td>  
  42.                     <td><input type="text" name="age"/></td>  
  43.                 </tr>  
  44.                 <tr>  
  45.                     <td>电子邮件:</td>  
  46.                     <td><input type="text" name="email"/></td>  
  47.                 </tr>  
  48.                 <tr>  
  49.                     <td>电话号码:</td>  
  50.                     <td><input type="text" name="phone" /></td>  
  51.                 </tr>  
  52.                 <tr>  
  53.                     <td><input type="submit" value="注册新用户" onclick="return checkInfo();"/></td>  
  54.                     <td><input type="reset" value=" 重新填写 " /></td>  
  55.                 </tr>  
  56.             </table>  
  57.         </form>  
  58.     </body>  
  59. </html>  

 

image对象

    image对象代表嵌入的图像。

image 对象的事件句柄

onerror图片加载失败触发此事件

onload图片加载成功触发此事件

参考文档:http://www.w3school.com.cn/jsref/dom_obj_image.asp

案例:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <script>  
  3.         function test(){  
  4.             span.innerText="加载失败";  
  5.         }  
  6.         function test1(){  
  7.             span.innerText="加载成功";  
  8.         }  
  9.     </script>  
  10.     </head>  
  11.     <body>  
  12.         <img alt="dog" src="2.jpg" onerror="return test()" onload="return test1()">  
  13.         <span id="span"></span>  
  14.     </body>     
  15. </html>  

 

all对象

    all集合返回对文档中所有HTML元素的引用。

基本语法:

document.all[i];

document.all[name];

document.all.tags[tagname];

参考文档:http://www.w3school.com.cn/jsref/coll_doc_all.asp

案例:

function test2(){

    var myalls=document.all;

    //可以将所有的html元素都取出来

    for(var i=0;i<myalls.length;i++){

        window.alert(myalls[i].nodeType+" "+myalls[i].nodeName);

    }

}

 

 

table对象

 

    table对象代表一个HTML表格。

cells 集合返回表格中所有单元格的一个数组。

rows 集合返回表格中所有行(TableRow 对象)的一个数组。

参考文档:http://www.w3school.com.cn/jsref/dom_obj_table.asp

案例:

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <html>  
  2.     <head>  
  3.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
  4.         <script type="text/javascript">  
  5.             function test1(){  
  6.                 // 取出所有行  
  7.                 var rows = mytab.rows;  
  8.                 window.alert(rows.length);  
  9.                 window.alert(rows[1].cells[0].innerText);  
  10.                 for(var i = 0; i mytab.rows.length; i++){  
  11.                     // 取出一行  
  12.                     var row = mytab.rows[i];  
  13.                     // 对该行遍历  
  14.                     for(var j = 0; j row.cells.length; j++){  
  15.                         // 取出项数据  
  16.                         var cell = row.cells[j];  
  17.                         window.alert(cell.innerText);  
  18.                     }  
  19.                 }  
  20.             }  
  21.   
  22.             // 删除一行  
  23.             function test2(){  
  24.                 mytab.deleteRow(1);  
  25.             }      
  26.   
  27.             // 插入一行  
  28.             function test3(){  
  29.                 // 插入行  
  30.                 var tableRow = mytab.insertRow(4);  
  31.                 // 插入项  
  32.                 tableRow.insertCell(0).innerText = "赵六";  
  33.                 tableRow.insertCell(1).innerText = "23";  
  34.             }  
  35.         </script>  
  36.     </head>  
  37.     <body>  
  38.         <table border="1px" id="mytab">  
  39.             <tr>  
  40.                 <td>姓名</td>  
  41.                 <td>年龄</td>  
  42.             </tr>  
  43.             <tr>  
  44.                 <td>张三</td>  
  45.                 <td>20</td>  
  46.             </tr>  
  47.             <tr>  
  48.                 <td>李四</td>  
  49.                 <td>22</td>  
  50.             </tr>  
  51.             <tr>  
  52.                 <td>王五</td>  
  53.                 <td>21</td>  
  54.             </tr>  
  55.         </table>  
  56.         <input type="button" value="button" onclick="test1()"/>  
  57.         <input type="button" value="delete" onclick="test2()"/>  
  58.         <input type="button" value="insert" onclick="test3()"/>  
  59.     </body>  
  60. </html>  

 

 

综合案例:下拉列表左右选择

 

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <!DOCTYPE html>  
  2. <html>  
  3.     <head>  
  4.         <meta charset="UTF-8">  
  5.         <title>下拉列表左右选择</title>  
  6.     </head>  
  7.     <body>  
  8.         <table border="1" width="600" align="center">  
  9.             <tr>  
  10.                 <td>分类名称</td>  
  11.                 <td><input type="text" name="cname" value="手机数码" /></td>  
  12.             </tr>  
  13.             <tr>  
  14.                 <td>分类描述</td>  
  15.                 <td><textarea name="cdesc" rows="4" cols="20">手机数码类商品</textarea></td>  
  16.             </tr>  
  17.             <tr>  
  18.                 <td>分类商品</td>  
  19.                 <td>  
  20.                     <span style="float: left;">  
  21.                         <font color="green" face="宋体">已有商品</font><br/>  
  22.                         <select multiple="multiple" style="width: 100px;height: 200px;" id="leftgoods">  
  23.                             <option>魅族MX5</option>  
  24.                             <option>IPhone7</option>  
  25.                             <option>小米5</option>  
  26.                             <option>华为P8</option>  
  27.                             <option>小米Note</option>  
  28.                             <option>小米MAX</option>  
  29.                         </select>  
  30.                         <p><href="#" style="padding-left: 20px;" onclick="selectGoods(false,'ltr')">>></a></p>  
  31.                         <p><href="#" style="padding-left: 20px;" onclick="selectGoods(true,'ltr')">>>></a></p>  
  32.                     </span>  
  33.                     <span style="float: right;">  
  34.                         <font color="red" face="宋体">未有商品</font><br/>  
  35.                         <select multiple="multiple" style="width: 100px;height: 200px;" id="rightgoods">  
  36.                             <option>三星Note3</option>  
  37.                             <option>魅族Pro 6</option>  
  38.                         </select>  
  39.                         <p><href="#" onclick="selectGoods(false,'rtl')"><<</a></p>  
  40.                         <p><href="#" onclick="selectGoods(true,'rtl')"><<<</a></p>  
  41.                     </span>  
  42.                 </td>  
  43.             </tr>  
  44.             <tr>  
  45.                 <td colspan="2">  
  46.                     <input type='submit' value="修改" />  
  47.                 </td>  
  48.             </tr>  
  49.         </table>  
  50.         <script type="text/javascript">  
  51.             function $(id) {  
  52.                 return document.getElementById(id);  
  53.             }  
  54.             var leftGoodsEle = $("leftgoods");  
  55.             var rightGoodsEle = $("rightgoods");  
  56.             // 移动商品  
  57.             function selectGoods(isAll,direct) {  
  58.                 if (direct == 'ltr' && isAll) {  
  59.                     moveAllGoods(leftGoodsEle, rightGoodsEle);  
  60.                 } else if (direct == 'ltr' && !isAll) {  
  61.                     moveSelectGoods(leftGoodsEle, rightGoodsEle);  
  62.                 } else if (direct == 'rtl' && isAll) {  
  63.                     moveAllGoods(rightGoodsEle, leftGoodsEle);  
  64.                 } else if (direct == 'rtl' && !isAll) {  
  65.                     moveSelectGoods(rightGoodsEle, leftGoodsEle);  
  66.                 }  
  67.             }  
  68.             // 将选中的移到另一边  
  69.             function moveSelectGoods(from, to) {  
  70.                 var childNode = from.childNodes;  
  71.                 for (var i = 0; i childNode.length;) {  
  72.                     // 移动过去后数组长度会-1,所以不需要i++  
  73.                     // 如果该节点没被选中,则i++,选择下一个结点  
  74.                     if (childNode[i].selected) {  
  75.                         to.appendChild(childNode[i]);  
  76.                     } else {  
  77.                         i++;  
  78.                     }  
  79.                 }  
  80.             }  
  81.                
  82.             // 移动所有的商品到另一边  
  83.             function moveAllGoods(from, to) {  
  84.                 var childNode = from.childNodes;  
  85.                 for (var i = 0; i childNode.length;) {  
  86.                     to.appendChild(childNode[i]);  
  87.                 }  
  88.             }  
  89.               
  90.         </script>  
  91.     </body>  
  92. </html>  



 

 

 

----------参考《韩顺平.轻松搞定网页设计(html+css+js)》

posted @ 2017-01-12 19:59  天涯海角路  阅读(159)  评论(0)    收藏  举报