简体   繁体   English

从表中删除一行

[英]deleting a row from a table

I am trying to remove a row from a html table using javascript. 我正在尝试使用javascript从html表中删除一行。 I know their is a function DOM function that deletes the row but I have my table in a form so when i delete the row it deletes the form to so my buttons do not work. 我知道他们是一个函数DOM函数,它删除行,但是我的表格位于表格中,因此当我删除行时,它会将表格删除,因此我的按钮不起作用。 Any ideas to solve this problem? 有解决这个问题的想法吗?

` `

<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);

}

You should try and change the id from table to something that is unique. 您应该尝试将id从表更改为唯一的东西。 Specifically change the following lines: <table style="width:100%" id = "table" > and update this one to reflect the previous snippet getElementById("table") 具体更改以下几行: <table style="width:100%" id = "table" >并更新此内容以反映以前的代码段getElementById("table")

One other thing you should try, is to close the form tag after the table tag 你应该尝试的另一件事,是要关闭form 标签table标签

You can place your <form> outside of the <table> and refer to it using the form="" attribute on your inputs. 您可以将<form>放在<table> <form>之外,并在输入中使用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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM