我正在嘗試在洗掉表中的資料之前添加確認訊息。但我不知道如何以及在哪里放置代碼。我嘗試查找其他代碼,但它不起作用。
這是我的代碼:
<?php $a = 0?>
<?php while ($row = mysqli_fetch_array($res)) {
echo "<tr id=".$a .">
<th scope='row' class='row-data'>".$row['user_id']."</th>
<td class='row-data'>".$row['full_name']."</td>
<td class='row-data'>".$row['user_name']."</td>
<td><input type='button'
value='EDIT'
onclick='editUser()'' /></td>
<td><input type='button'
value='DELETE'
onclick='deleteUser()' /></td>
</tr>
</tbody>";
}; ?>
function deleteUser() {
var rowId =
event.target.parentNode.parentNode.id;
//this gives id of tr whose button was clicked
var data =
document.getElementById(rowId).querySelectorAll(".row-data");
/*returns array of all elements with
"row-data" class within the row with given id*/
var uID = data[0].innerHTML;
document.getElementById("toBeEdit").value = uID;
document.getElementById("taskStatus").value = 'delete';
//alert("ID: " uID);
const form = document.getElementById('editForm');
form.submit();
}
</script>
uj5u.com熱心網友回復:
confirm()您可以在deleteUser()函式中使用內置方法。請看下面的代碼,
function deleteUser() {
if(confirm('Are you sure want to delete user?')){
var rowId =
event.target.parentNode.parentNode.id;
//this gives id of tr whose button was clicked
var data =
document.getElementById(rowId).querySelectorAll(".row-data");
/*returns array of all elements with
"row-data" class within the row with given id*/
var uID = data[0].innerHTML;
document.getElementById("toBeEdit").value = uID;
document.getElementById("taskStatus").value = 'delete';
//alert("ID: " uID);
const form = document.getElementById('editForm');
form.submit();
}
}
該confirm()方法顯示一個對話框,其中包含一條訊息、一個確定按鈕和一個取消按鈕。
如果用戶單擊“確定”,則該confirm()方法回傳 true,否則回傳 false。
uj5u.com熱心網友回復:
---> you should to add this code include your delete function
if(window.confirm("你想洗掉這個資料嗎")){
--> 你的 js 代碼 <--
}else{ 回傳假;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/468501.html
標籤:javascript php mysql 粗鲁
上一篇:為什么GoogleChromeMobile中的“日期”和“時間”條目顯示不正確?
下一篇:上傳multer后無法保存檔案
