[英]Hide button inside a table after form submit?
因此,我試圖在按Delete后使包含刪除按鈕的行隱藏到.hide中。 問題是..刪除按鈕提交了一個表單,我無法預定義我的按鈕類/ ID,因為它多次被蜂鳴(PHP腳本讀取一個目錄,然后將所有文件放在表中)
這是當前的腳本,它確實在后台發布了表單,但是它沒有隱藏元素,我自己嘗試了一些東西,但是腳本最終隱藏了頁面上的所有按鈕,或者根本無法工作..
按鈕蜂鳴回聲:
echo "<input type='submit' value='delete' name='submit'>";
其背后的腳本:
$("#delform").submit(function() {
var url = "../../setdel.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#delform").serialize(), // serializes the form's elements.
success: function(data)
{
// location.reload(); // show response from the php script.
}
});
return false; // avoid to execute the actual submit of the form.
});
捕獲按鈕的onclick而不是捕獲提交。 例:
echo "<input type='submit' value='delete' name='delete' class='trigger_delete'>";
// ^^ don't name your buttons as submit
// it will conflict to .submit() method
在JS上:
$('.trigger_delete').on('click', function(e){
e.preventDefault(); // prevent triggering submit
var url = "../../setdel.php";
$.ajax({
type: 'POST',
url: url,
data: $("#delform").serialize(),
success: function(response) {
console.log(response);
$(e.target).closest('tr').hide(); // or .fadeOut();
}(e) // <--- this one
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.