除了第一行之外,如何使用 Javascript 删除表上的所有行?这是我的代码,我想创建一个函数来删除除第一行之外的所有行并将其更改为“您的团队名册为空”。我需要 Javascript 代码。
<script type="text/javascript">
/* <![CDATA[ */
var flag = true;
function addBowler() {
if(flag){
document.getElementById("bowlerList").deleteRow(0);
flag = false;
}
var removeButton = "<input type='button' value='remove' onclick='removePlayer()' /> ";
var newBowler = document.getElementsByName('bowlersName')[0].value;
var tr = document.createElement('tr');
var td = tr.appendChild(document.createElement('td'));
td.innerHTML = newBowler + removeButton;
document.getElementById("bowlerList").appendChild(tr);
}
function removePlayer() {
}
/* ]]> */
</script>
</head>
<body>
<!-- HEADER 1 & 2 -->
<h1>Central Valley Lanes</h1>
<h2>2008 Bowling Teams</h2>
<p>Bowler's name:<input type="text" name="bowlersName" size="15" />
<input type="button" value="Add Bowler" onclick="addBowler()" /></p>
<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>
<p><input type="submit" value="Submit" /></p>
</form>
</body>