为了账号安全,请及时绑定邮箱和手机立即绑定

求解答,为什么出不来结果啊?

<!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=utf-8" />    

<title>无标题文档</title>    

<script type="text/javascript">    

function addt(){    

//创建表格    

var ntable=document.createElement("table");    

ntable.setAttribute("width","300");    

ntable.setAttribute("border","1");    

//创建ntbody    

var ntbody=document.createElement("tbody");    

ntable.appendChild(ntbody);    

//创建第一行    

ntbody.insertRow(0);    

ntbody.insertRow(0).insertCell(0);    

ntbody.insertRow(0).cells[0].appendChild(document.createTextNode("ABC"));    

//创建第二行    

ntbody.insertRow(1);    

ntbody.insertRow(0).insertCell(0);    

ntbody.insertRow(1).cells[0].appendChild(document.createTextNode("123"));    

//将表格放到document中    

document.body.appendChild("ntable");    

}    

</script>    

</head>    

<body>    

<input type="button" value="create a table" onclick="addt()">    

</body>    

</html>    


正在回答

1 回答

<!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=utf-8" />    

<title>无标题文档</title>    

<script type="text/javascript">    

function addt(){    

//创建表格    

var ntable=document.createElement("table");    

ntable.setAttribute("width","300");    

ntable.setAttribute("border","1");    

//创建ntbody    

var ntbody=document.createElement("tbody");    

ntable.appendChild(ntbody);    

//创建第一行    

ntbody.insertRow(0).insertCell(0).appendChild(document.createTextNode("ABC"));    

//创建第二行      

ntbody.insertRow(0).insertCell(0).appendChild(document.createTextNode("123"));    

//将表格放到document中    

document.body.appendChild(ntable);    

}    

</script>    

</head>    

<body>    

<input type="button" value="create a table" onclick="addt()">    

</body>    

</html>    

我把你的代码做了下修改,现在可以了。你自己对比着看看吧。

0 回复 有任何疑惑可以回复我~
#1

小婆娘

创建第二行那里,我写错了。 ntbody.insertRow(1).insertCell(0)
2015-12-23 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

求解答,为什么出不来结果啊?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信