求救!特急!!!appendchild的问题

lyh_mzsm 2012-07-17 10:18:45

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="kikimail.WebForm1" %>

<!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 runat="server">
<title></title>
<script type="text/javascript">
function GroupTableCreat() {
var divt = document.getElementById("divUserGroup");
var tablet = "<table cellspacing='0' rules='all' border='0' id='grvContent2' style='position:relative;left:45pt;border-width:0px;width:80%;border-collapse:collapse;'><tr class='t_row_bg'><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk0' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk1' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk2' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk3' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td></tr><tr class='t_row_bg'><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk4' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk5' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk6' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk7' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td></tr><tr class='t_row_bg'><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk8' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk9' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk10' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk11' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td></tr></table>";
divt.appendChild(tablet);
}

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr><td><input type="button" value="copy" onclick="GroupTableCreat();" /></td></tr>
</table>
</div>
<div>
<table cellspacing='0' rules='all' border='0' id='grvContent' style='position:relative;left:45pt;border-width:0px;width:80%;border-collapse:collapse;'><tr class='t_row_bg'><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk0' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk1' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk2' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk3' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td></tr><tr class='t_row_bg'><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk4' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk5' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk6' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk7' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td></tr><tr class='t_row_bg'><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk8' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk9' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk10' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk11' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td></tr></table>
</div>
<div id="divUserGroup">

</div>
</form>
</body>
</html>


代码如上,点击copy按钮时抱错;
需要追加的table显示是没有任何问题的,但是往div中添加就嫁不上去,抱错了
...全文
149 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lyh_mzsm 2012-07-17
  • 打赏
  • 举报
回复
太谢谢了!!!
DemoChen 2012-07-17
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
divt.innerHTML+=tablet;
[/Quote]

+++
似梦飞花 2012-07-17
  • 打赏
  • 举报
回复

divt.innerHTML+=tablet;
kunkkaCoco 2012-07-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

tablet不是对象,是字符串,所以不行。修改一下, 转成对象类型即可
JScript code

function GroupTableCreat() {
var divt = document.getElementById("divUserGroup");
……
[/Quote]
对滴,用jquery的话是可以这么干的,直接append(tablet);
似梦飞花 2012-07-17
  • 打赏
  • 举报
回复
divt.appendChild(tablet);
改成
divt.innerHTML=tablet;
试试
chenyang37 2012-07-17
  • 打赏
  • 举报
回复
tablet不是对象,是字符串,所以不行。修改一下, 转成对象类型即可

function GroupTableCreat() {
var divt = document.getElementById("divUserGroup");
var tablet = "<table cellspacing='0' rules='all' border='0' id='grvContent2' style='position:relative;left:45pt;border-width:0px;width:80%;border-collapse:collapse;'><tr class='t_row_bg'><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk0' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk1' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk2' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk3' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td></tr><tr class='t_row_bg'><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk4' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk5' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk6' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk7' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td></tr><tr class='t_row_bg'><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk8' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk9' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk10' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td><td class='Cell_Normal' align='center' style='width:5%;'><input type='checkbox' name='chk11' /></td><td class='Cell_Normal' align='left' style='width:15%;'>on</td></tr></table>";
var wrap = document.createElement("div");
wrap.innerHTML = tablet;
var tab = wrap.childNodes;
divt.appendChild(tab[0]);
}

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧