php javascript删除单个行


php javascript delete individual row

我有一个php表,我希望能够删除我选择的行,但我不知道如何进行。这是我删除的javascript:

// When a delete button is pressed in one of the rows 
function deleteCurrentRow(whatrow)
{
  //deletes the approriate row according to what button was pressed
  if (hasLoaded) {
    var delRow = whatrow.parentNode.parentNode;
    deleteRows(delRow);//sends the row for deletion to the function to be deleted
  }
}

function deleteRows(rowforDeletion)
{
  if (hasLoaded) {
      var rowPos = rowforDeletion.sectionRowIndex;//postion of the row for deletion
      rowforDeletion.parentNode.deleteRow(rowPos);//deletes row
      increment = increment -1;
  }
}

这是我的php表:

<table border="1" cellspacing="5" id="tblmarkscheme" style="float: center;">
  <thead>
    <tr>
      <th colspan="5">Template</th>
    </tr>
    <tr>
      <th>Mark</th><th>Criteria</th><th>Delete</th>
    </tr>
  </thead>
  <tbody>
    <?php
      $query = "SELECT maxMark, criteria FROM mark ";
      $result = mysql_query($query);

      while ($row = mysql_fetch_array($result))
      { 
        echo "<tr>";
        echo "<td>" ."<input type = text name = text size = 1 id = mark value = ". $row['maxMark'].">" ."</td>";
        echo "<td>"."<textarea>".$row['criteria']. "</textarea>"."</td>";
        echo "<td>"."<input type = button value = Delete onclick = deleteCurrentRow(this);/>"."</td>";
        echo "</tr>";
      }

    ?>
  </tbody><!--elements added onload and when button pressed -->
</table>

我想通过按下按钮来删除表中的各个行

这里有一个例子;如果你点击一个按钮,它的行就会被删除:

<!DOCTYPE HTML>
<html>
    <head>
        <script type="text/javascript">
            var p = {
                deleteRow: function(row) {
                document.getElementById("mytable").deleteRow(row.rowIndex);
                }
            };
        </script>
    </head>
    <body>
        <table id="mytable">
            <tr>
                <td><input type="button" value="row1" onclick="p.deleteRow(this)"/></td>
            </tr>
            <tr>
                <td><input type="button" value="row2" onclick="p.deleteRow(this)"/></td>
            </tr>
        </table>
    </body>
</html>

实际上这是一个html表。

您将需要使用javascript来删除行。

http://www.w3schools.com/jsref/met_table_deleterow.asp

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
function del(id)
{
 var info = 'id=' + id;
    if(confirm("Are you sure you want to delete this Record?")){
        var html = $.ajax({
        type: "GET",
        url: "deletCourse.php",
        data: info,
        async: false ,
         success: function() {
    window.location.reload(true);}
        }).responseText;

    }
}
</script>
<?php
$link=mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("cart");
$sql=mysql_query("SELECT * FROM `details`");
echo "<table>";
echo "<tr><th>Name</th><th>NO of Items</th></tr>";
while($row = mysql_fetch_assoc($sql)){
  echo '<tr class="record">';
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['num'] . "</td>";
  echo '<td><div align="center"><a href="#"  id="' . $row['id'] . '" onclick="del('.$row['id'].')">delete</a></div></td>';
  echo '</tr>';
}
echo "</table>";
mysql_close($link);
?>``