该小程序的主题框架都有dom技术创建,已经给予良好的注释。有Js对表格的创建一个对表格栏目的删除。这个小程序耗时3小时,没办法,这就是我的水平。



<!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.οnlοad=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).οnclick=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_.οnclick=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" οnclick="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>
上面代码基本包含各种复杂问题,也是对前人技术的一个总结吧。