0

我正在使用 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>

这是脚本:

$("#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');
});
4

3 回答 3

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.. 
于 2013-04-05T18:53:23.113 回答
0

I made a simple moch-up on jsFiddle www.jsfiddle.net/bphamous/rQ3MC and it appears to be working. Issue must be in my code.

于 2013-04-05T19:07:03.947 回答
0

像这样使用 Java 脚本的 cofirm() 时有什么问题:

function delete(Id){
   boolean b = confirm("Deleting : "+Id", Are you sure ..??");
   if(b == true){
    // make the delete process here ...
   }
   else{
      // do dtuff .....
   }
 }
于 2013-04-05T20:02:01.130 回答