添加< TR>到< TABLE>与.appendChild [英] Adding <TR> to a <TABLE> with .appendChild
本文介绍了添加< TR>到< TABLE>与.appendChild的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< script type =text / javascript>
/ *<![CDATA [* /
function addBowler(){
var newBowler = document.getElementsByName('bowlersName').value;
var tr = document.createElement('tr');
var td = tr.appendChild(document.createElement('td'));
td.innerHTML = newBowler;
document.getElementById(bowlerList)。appendChild(tr);
}
/ *]]> * /
< / script>
< / head>
< body>
<! - HEADER 1& 2 - >
< h1> Central Valley Lane< / h1>
< h2> 2008年保龄球队< / h2>
Bowler's name< input type =textname =bowlersNamesize =15/>< input type =buttonvalue =Add Bowleronclick =addBowler()/> ;
< h2>团队名单< / h2>
< form action =FormProcessor.htmlmethod =get>
< table border =1id =bowlerList>
< tr>
< td id =empty>您的球队名单是空的< / td>
< / tr>
< / table>
< br />
< input type =buttonvalue =提交名单/>
< / form>
< / body>
解决方案
试着改变这一行:
td.innerHTML =(+ bowlersName +);
至此:
td.innerHTML =(+ bowlersName +);
Everytime I try to enter a new cell to the table it doesn't add the text in the bowlersName value. Is there something wrong with my Javascript code? It says "undefined".
<script type="text/javascript">
/* <![CDATA[ */
function addBowler() {
var newBowler = document.getElementsByName('bowlersName').value;
var tr = document.createElement('tr');
var td = tr.appendChild(document.createElement('td'));
td.innerHTML = newBowler;
document.getElementById("bowlerList").appendChild(tr);
}
/* ]]> */
</script>
</head>
<body>
<!-- HEADER 1 & 2 -->
<h1>Central Valley Lanes</h1>
<h2>2008 Bowling Teams</h2>
Bowler's name <input type="text" name="bowlersName" size="15" /><input type="button" value="Add Bowler" onclick="addBowler()" />
<h2>Team Roster</h2>
<form action="FormProcessor.html" method="get">
<table border="1" id="bowlerList">
<tr>
<td id="empty">Your team roster is empty</td>
</tr>
</table>
<br />
<input type="button" value="Submit Roster" />
</form>
</body>
解决方案
Try to change this line:
td.innerHTML = (" + bowlersName + ");
To this:
td.innerHTML = "(" + bowlersName + ")";
这篇关于添加< TR>到< TABLE>与.appendChild的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文