你好我有一个删除确认对话框和2个存储href的变量和一个存储删除行调用的变量。问题是在我按下删除按钮之前它已调用的删除表行,我不知道原因。 href工作得很好。这是我的js:
<script>
$(".cart_quantity_delete").click(function(e){
e.preventDefault();
var tablerow = $(this).closest('tr').remove();
var href = $(this).attr('href');
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Delete all items": function() {
$( this ).dialog( "close" );
$.ajax({
type: "POST",
url: href,
success: function(result) {
tablerow
}
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
</script>
答案 0 :(得分:0)
<script>
$(".cart_quantity_delete").click(function(e){
e.preventDefault();
var tablerowObj = $(this);
var href = $(this).attr('href');
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Delete all items": function() {
$( this ).dialog( "close" );
$.ajax({
type: "POST",
url: href,
success: function(result) {
tablerow(tablerowObj);
}
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
function tablerow( obj ){
obj.closest('tr').remove();
}
</script>
答案 1 :(得分:0)
移动&#34;删除&#34;函数调用成功&#34;回调:
从这里开始:
var tablerow = $(this).closest('tr');
并致电&#34;删除&#34;在成功回调中:
success: function(result) {
tablerow.remove();
}