标签:
实例1:一串跟着鼠标飞舞的div
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> div {width:10px; height:10px; background:red; position:absolute;} </style> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>一串跟着鼠标飞舞的div </title> <script> window.onload=function () { var aDiv=document.getElementsByTagName(‘div‘); var i=0; document.onmousemove=function (ev) { var oEvent=ev||event; //兼容浏览器的事件对象的写法,event是IE的写法,传参是火狐的写法 for(i=aDiv.length-1;i>0;i--) { aDiv[i].style.left=aDiv[i-1].style.left; aDiv[i].style.top=aDiv[i-1].style.top; } aDiv[0].style.left=oEvent.clientX+‘px‘; aDiv[0].style.top=oEvent.clientY+‘px‘; }; }; </script> </head> <body> <div></div> <div></div> <div></div> <!--------------此处省略很多div--------> </body> </html>
2.document是<!DOCTYPE 和html标签的父级
标签:
原文地址:http://www.cnblogs.com/lanyueff/p/4604104.html