javascript - 运行甜蜜警报脚本时如何运行另一个 JavaScript 函数
问题描述
我想实现javascript函数来删除确认。单击ok
确认警报表的按钮后,tr
应从前端删除。我已经用于$("#confirm-btn-alert").click(function()
确认警报,哪个在sweet-alert-script.js
哪function SomeDeleteRowFunction(o)
个newfile.html
用于删除tr
sweet-alert-script.js
$(document).ready(function(){
$("#confirm-btn-alert").click(function(){
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
swal("Poof! Your imaginary file has been deleted!", {
icon: "success",
});
} else {
swal("Your imaginary file is safe!");
}
});
});
});
新文件.html
<script>
function SomeDeleteRowFunction(o) {
var p=o.parentNode.parentNode;
p.parentNode.removeChild(p);
}
</script>
解决方案
您可以尝试与单击确认按钮相同的方法!用以下内容
更改<script> function
$(document).ready(function(){
$("#ok-button-id").click(function(o){
var p=o.parentNode.parentNode;
p.parentNode.removeChild(p);
})
});
或者,如果<tr>
有身份证,这对你来说很容易。
<tr id="myTableRow"><td>Confirmation message here</td></tr>
$(document).ready(function(){
$("#ok-button-id").click(function(){
$('#myTableRow').remove();
})
});
这是另一种方式
$(document).ready(function(){
$('#myTableID tr').click(function(){ //Here 'this' will be the table row
$(this).remove();
return false;
})
});
推荐阅读
- java - 无法通过套接字将 Python 消息发送到 Java
- c - 如何修复结构的分配大小
- javascript - 如何在图像画布上创建褪色光标轨迹?
- bash - 使用 xmlstarlet 从 xml 中提取元素
- java - 当我将 MainActivity 拆分为多个类时,Android 应用程序崩溃
- linux - 在 Linux 上部署 asp.net core 应用程序 - 重定向 url 问题
- python - Python编码base64不期望正确的结果?
- php - 正则表达式检查给定字符之前和之后的第一个字符
- javascript - 天才聊天杂乱无章的消息
- ios - 如何在不包含依赖项的情况下获取 .framework 文件