读书人

innerHTML赋值丢失对象,该如何处理

发布时间: 2012-03-01 10:25:46 作者: rapoo

innerHTML赋值丢失对象
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> </title>
<script>
function onTwiClick(obj){
var place = obj.all[0].innerText;
var expstr,start,end;
expstr = " ";
start = " <tr id= ' " + obj.all[1].innerText + " ' bgcolor= '#F7F3F7 '> ";
end = " </tr> ";
expstr = start + obj.innerHTML + end;
oldexp = document.getElementById( "ResultSB ").innerHTML;
document.getElementById( "ResultSB ").innerHTML =
oldexp + " <br> " + expstr;
}
</script>
</head>
<body bgcolor= "#42A6E7 ">
<form name= " " method= "post " action= " ">
<div style= "border-style:solid; ">
<table cellpadding= "0 " cellspacing= "1 ">
<span id= "ResultSA ">
<tr id= '0 ' ondblclick= 'onTwiClick(this) ' bgcolor= '#F7F3F7 '>
<td nowrap= 'nowrap ' style= ' '> 10 </td>
<td nowrap= 'nowrap ' style= 'display:block; '> 0000000 </td>
<td nowrap= 'nowrap ' style= 'display:block; '> 000000000000 </td>
</tr>
<tr id= '1 ' ondblclick= 'onTwiClick(this) ' bgcolor= '#F7F3F7 '>
<td nowrap= 'nowrap ' style= ' '> 11 </td>
<td nowrap= 'nowrap ' style= 'display:block; '> 0000000 </td>
<td nowrap= 'nowrap ' style= 'display:block; '> 000000000000 </td>
</tr>
</span>
</table>
</div>
<div style= "border-style:solid; ">
<table cellpadding= "0 " cellspacing= "1 ">


<span id= "ResultSB ">   </span>
</table>
</div>
</form>
</body>
</html>
====================页面最初效果===================
-----------------------|
10|0000000|000000000000|
-----------------------|
11|0000000|000000000000|
-----------------------|
双击其中一行,将被击中行的赋值到下边,效果如下

10
0000000
000000000000
11
0000000
000000000000
现在的问题是,被赋值到下边的内容,没有了列,成了三行,这是为什么.
我在js里alert(obj.innerHTML),是没有tr的,是为什么?

[解决办法]
不要对表格使用innerHTML,请使用insertRow,insertCell等
详细介绍和例子参见

http://msdn.microsoft.com/workshop/author/tables/buildtables.asp
http://www.cnblogs.com/waxdoll/archive/2005/04/18/140049.html

读书人网 >JavaScript

热点推荐