我正在使用jQuery UI对话框来确认删除请求。当用户确认删除请求时,我正在尝试将ID传递给AJAX帖子。提前感谢您的任何见解。
这是HTML:
<table width="100%" cellspacing="1" cellpadding="5" border="0" class="detailTbl" id="myTable">
<tbody>
<tr class="divider" id="editRow220">
<td align="top">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </td>
<td align="top">
<a class="btn_delete deleteMe form-tip" href="#" id="220" title="Delete this item"></a>
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span>
</td>
</tr>
</tbody>
</table>
这是SCRIPT:
$("#myTable tbody").on("click", "a.deleteMe", function (e) {
e.preventDefault();
var RemoveID = $(this);
alert(RemoveID.attr("id")); // ***correct ID here ***
var $myDialog = $('<div></div>')
.html('Are you sure you want to delete this item?')
.dialog({
autoOpen: false,
title: 'Confirmation',
buttons: {"Yes": function(e) {
alert(RemoveID.attr("id")); // ***RemoveID is undefined here***
// AJAX Call here //
return true;
}, "No": function() {
$(this).dialog("close");
return false;
}
}
});
return $myDialog.dialog('open');
});
答案 0 :(得分:0)
这可能是一个草率的解决方案,但您可以尝试将ID分配给全局变量,然后使用它:
var mID;
$("#myTable tbody").on("click", "a.deleteMe", function (e) {
e.preventDefault();
mID = $(this).attr("id");
var $myDialog = $('<div></div>')
.html('Are you sure you want to delete this item?')
.dialog({
autoOpen: false,
title: 'Confirmation',
buttons: {"Yes": function(FmoPmoToRemove) {
alert(mID); //shouldnt be undefined anymore
..rest of code..
答案 1 :(得分:0)
我在jsFiddle www.jsfiddle.net/bphamous/rQ3MC做了一个简单的moch-up,它似乎正在工作。问题必须在我的代码中。
答案 2 :(得分:0)
在Javascript中使用confirm()时会出现什么问题:
function delete(Id){
boolean b = confirm("Deleting : "+Id", Are you sure ..??");
if(b == true){
// make the delete process here ...
}
else{
// do dtuff .....
}
}