- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title> 本周周末完成 </title>
- <meta name="Generator" content="EditPlus">
- <meta name="Author" content="">
- <meta name="Keywords" content="">
- <meta name="Description" content="">
- <script type="text/javascript">
- // window.onload=loadbody()
- function loadbody(){
- var para=document.getElementById("para"); //获取表格对象
- var table =document.getElementById("table");
- if(table==null){
- table=document.createElement("table");
- table.id="table";
- }else{
- para.removeChild(table);
- table=document.createElement("table");
- table.id="table";
- }
- var xwidth=document.getElementById("xwidth").value;
- var yheight=document.getElementById("yheight").value;
- for(var i=0;i<xwidth;i++){ //循环创建表格
- var tr_=document.createElement("tr");
- for(var j=0;j<yheight;j++){
- var td_=document.createElement("td");
- var node=document.createTextNode("");
- td_.id="td"+i+j;//设置表格内部id参数
- td_.style.height="60px";
- td_.style.width="60px";
- td_.appendChild(node);
- tr_.appendChild(td_);
- }
- table.appendChild(tr_);
- }
- table.border="1px";
- para.appendChild(table);
- //para.style.background="";
- createmousesite();//表格生成后开始运行
- }
- var str="";
- var t=0;
- function createmousesite(){//创建位置
- clearTimeout(t);
- if((str!="")&&(str!=null)){
- document.getElementById(str).innerHTML="";
- document.getElementById(str).onclick=null;
- }
- var xwidth=document.getElementById("xwidth").value;
- var yheight=document.getElementById("yheight").value;
- var x=parseInt( Math.random()*xwidth);
- var y=parseInt(Math.random()*yheight);
- var td_=document.getElementById("td"+x+y);
- this.str="td"+x+y;//保留当前Id
- td_.innerHTML="<img src='images/cai.gif'/>";//将图片插入网格处
- td_.onclick=function (){
- heatmouse();//加载函数
- };
- t=setTimeout("createmousesite()",1000);//一秒钟更换一次位置
- }
- var count=0;
- function heatmouse(){
- count++;
- document.getElementById("count").innerHTML=count*10+"分";
- }
- function stopmouse(){//停止运动
- clearTimeout(t);
- }
- </script>
- <style type="text/CSS">
- </style>
- </head>
- <body ><!--这里提供一个初始化的设置-->
- <div id="setvalue" style="width:600px;height:40px">
- <table border="0" >
- <tr>
- <td>
- <input type="button" value="start" onclick="loadbody()"/>
- </td>
- <td>addvalue:</td>
- <td>
- x:<input type="text" id="xwidth" value="4"/>
- </td>
- <td>
- y:<input type="text" id="yheight" value="4"/><!--默认参数-->
- </td>
- </tr>
- <tr>
- <td id="count" style="color:red;height:40px"></td>
- </tr>
- </table>
- </div>
- <div id="para"><!--这里为主业务区域-->
- </div>
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/020120148349.html
来源: http://www.codesnippet.cn/detail/020120148349.html