【发布时间】:2014-09-08 09:44:00
【问题描述】:
我在使用 js 函数删除字段时遇到问题。首先,我生成这个和数据库表中的条目一样多:
function queryComposant($param) {
$query = "SELECT nom_" . $param . " FROM " . $param . ";";
$result = connectdb()->query($query)or die("Err " . $query);
$resultat = $result->fetch(PDO::FETCH_OBJ);
echo '<table border = "1" id="table' . $param . '">';
foreach ($resultat as $value) {
}
while ($resultat = $result->fetch(PDO::FETCH_OBJ)) {
echo '<tr>'
. '<form action="' . $param . 'Delete.php" method="post">';
$n = "nom_" . $param;
$nom = $resultat->$n;
echo '<td>' . $nom . '</td>'
. '<input id="' . $param . 'delete" type="hidden" name="delete" value="'.$nom.'" />'
. '<td><input type="button" onclick="remove();" value="Supprimer" /></td>'
. '</form>'
. '</tr>';
}
echo '</table>';
}
我想在每次点击“Supprimer”按钮时删除表格中的整个tr。
function remove(){
$().live('click',function(){
var whichtr = $(this).parent().parent();
whichtr.remove();
});
}
我做错了什么?我使用$(this).parent().parent(); 从button 到td 和从td 到tr 然后尝试删除它,但该功能只删除按钮。
我也试过了,没有成功:
function remove(){
$().live('click',function(){
var whichtr = $(this).closest("tr");
whichtr.remove();
});
}
【问题讨论】:
标签: javascript php jquery html xml