日期:2014-05-16  浏览次数:20402 次

关于给表格加一行的问题
比如我有如下这么个表格
<table>
<tr> <td> 1 </td> </tr>
</table>

现在js有这么一个字符串,如下:
var   s   =   " <tr> <td> 2 </td> </tr> "

问题
如何吧字符串s加到这个表格中,使网页中看到的效果如下:
<table>
<tr> <td> 1 </td> </tr>
<tr> <td> 2 </td> </tr>
</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> aaaa </title>
<link href= "css/css.css " rel= "stylesheet " type= "text/css " />
</head>
<body>
<table id= "tbl ">
<tr> <td> 1 </td> </tr>
</table>
<input type= "button " onclick= "cc() ">
<script>
function cc(){
alert( 's ')
var a=document.getElementById( "tbl ")
var b=a.insertRow(1)
var c=b.insertCell()
c.innerHTML= " <tr> <td> 2 </td> </tr> "
}
</script>
</body>
</html>