【发布时间】:2016-01-14 10:11:29
【问题描述】:
我想通过单击相应的删除按钮从我的 html 表中删除一行。发生的情况是,如果我使用确认框,那么一切正常,但我不想使用确认框而不是我想使用带有确定按钮的对话框,并且单击确定按钮时,它应该执行与它相同的功能使用确认框。我提供了两个代码,一个带有确认框,另一个带有对话框。帮助我对那个对话框做同样的事情。 确认框的jquery代码可以正常工作-
$(document).ready(function()
{
$('input[type=button]').click(function()
{
if (confirm("Are you sure you want to delete this row?"))
{
var ID = $(this).parent().parent().attr('id');
var data = 'id=' + ID ;
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "delete.php",
data: data,
cache: false,
success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
}
});
});
带有对话框的jquery代码-
$(document).ready(function(){
$('#modal').dialog({
autoOpen: false,
title: 'Delete Confirm Box',
width: 400,
buttons : [
{
text: 'OK',
click: function () {
$("#modal").dialog('close');
del_row();
alert("done");
}
},
{
text: 'Cancel',
click: function () {
$("#modal").dialog('close');
}
}
]
});
$('input[type=button]').click(function(){
$('#modal').dialog('open');
});
});
and the part which i want to execute on ok click of dialog box-
$('input[type=button]').click(function()
{
if (confirm("Are you sure you want to delete this row?"))
{
var ID = $(this).parent().parent().attr('id');
var data = 'id=' + ID ;
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "delete.php",
data: data,
cache: false,
success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
}
});
【问题讨论】:
-
如果我理解您要执行的操作,您只需将
input[type=button]单击处理程序中的代码复制到对话框的OK按钮单击处理程序中...?跨度> -
是的,实际上..但是这样做时,“this”关键字指的是对话框,而 this 指的是输入[type=button],因此更改发生在相应的行中。即。相应的行被删除..我尝试将该代码复制到确定按钮单击处理程序中,但它淡出整个页面
-
我如何包含 input[type=button ]click 的相应行..以便可以对其执行操作。