我正在尝试使用javascript从html表中删除一行。我知道他们是一个函数DOM函数,它删除行,但是我的表格位于表格中,因此当我删除行时,它会将表格删除,因此我的按钮不起作用。有解决这个问题的想法吗?
`
<table style="width:100%" id = "table" >
<tr>
<th>Ticket number</th>
<th>Class</th>
<th>Meal</th>
<th>Seat Number</th>
<th>Price</th>
</tr>
<%while(r.next()){ %>
<tr>
<td align="center"><form method="post" action="/AirportServer/html/Purchased.jsp">
<input type="radio" name="Flight-Num" value = "<%=r.getString("ticket_unique_num") %>">
<%=r.getString("ticket_unique_num") %> </td>
<td align="center"><%=r.getString("class")%></td>
<td align="center"><%=r.getString("meal") %></td>
<td align="center"><%=r.getString("seat_number") %></td>
<td align="center"><%=r.getString("fare") %></td>
</tr>
<%} %>
<button type="submit">Reserve Ticket</button>
</form>
</table>
<button onclick="filter()">Sort By low to High</button>
function filter(){
var x = document.getElementById("table");
x.deleteRow(1);
}
答案 0 :(得分:1)
您应该尝试将id从表更改为唯一的东西。具体更改以下几行:
<table style="width:100%" id = "table" >
并对其进行更新以反映上一小段getElementById("table")
您应该尝试的另一件事是在form
标记之后的{em> 之后关闭table
标记
答案 1 :(得分:0)
您可以将<form>
放在<table>
之外,并使用输入上的form=""
属性对其进行引用。
<form name="myForm" action="/foo" method="POST"></form>
<table>
<tr>
<input type="text" form="myForm">
</tr>
</table>
<button type="submit" form="myForm">Submit</button>