因为move的方法不光触发了TD的事件,也触发了TABLE的,所以每次都是新加进去的。可以看下面的代码就知道问题了<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script language="javascript">
function t(o)
{
o.removeChild(o.childNodes[0]);
var tbody=document.createElement("tbody");
o.appendChild(tbody);
var a=document.createElement("tr");
tbody.appendChild(a);
var b=document.createElement("td");
a.appendChild(b);
b.innerHTML="222";
b.onmousemove=function()
{
event.cancelBubble=true
this.style.backgroundColor="#FFF9C3";
this.style.borderLeft="1px dashed #FF6600";
}
}
</script>
</head> <body>
<table border="1" onmousemove="t(this)">
<tbody>
<tr> <td>111 </td> </tr>
</tbody>
</table>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script language="javascript">
function t(o)
{
o.removeChild(o.childNodes[0]);
var tbody=document.createElement("tbody");
o.appendChild(tbody);
var a=document.createElement("tr");
tbody.appendChild(a);
var b=document.createElement("td");
a.appendChild(b);
b.innerHTML="222";
b.onmousemove=function()
{
event.cancelBubble=true
this.style.backgroundColor="#FFF9C3";
this.style.borderLeft="1px dashed #FF6600";
}
}
</script>
</head> <body>
<table border="1" onmousemove="t(this)">
<tbody>
<tr> <td>111 </td> </tr>
</tbody>
</table>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script language="javascript">
function t(o)
{
o.removeChild(o.childNodes[0]);
var tbody=document.createElement("tbody");
o.appendChild(tbody);
var a=document.createElement("tr");
tbody.appendChild(a);
var b=document.createElement("td");
a.appendChild(b);
b.innerHTML="222";
b.onmousemove=function()
{
event.cancelBubble=true
this.style.backgroundColor="#FFF9C3";
this.style.borderLeft="1px dashed #FF6600";
}
b.ondbclick=function()
{
alert("YEAH");
}
}
</script>
</head> <body>
<table border="1" onmousemove="t(this)">
<tbody>
<tr> <td>111 </td> </tr>
</tbody>
</table>
</body>
</html>
加了一个双击事件,但没办法触发,这又是怎么回事?