2017-04-14 145 views
1

我有一個列表中刪除按鈕,由AJAX調用填充列表。這些按鈕可以觸發一個確認對話框,但是我不能在這個點擊事件處理程序中調用時顯示確認對話框。我需要單獨的處理程序嗎?我希望有人能指導我尋求解決辦法。jQuery確認()在附加的事件處理程序

$('#list').on('click', '.btnRemoveNote', function() {     
       $(this).confirm({ 
        msg: 'Do you really want to remove this?' 
       });      
      }); 

這是名單是如何產生的

function funcLoadList(racodeID) { 
    if (racodeID == null || racodeID == '') { console.log('bypassing list load, racodeid was null'); return; } 
    console.log("Load List function initiated for " + racodeID); 
    $('.table-row').remove(); 
    var url = '<%= Url.Action("MemberGetNoteList", "AccessCodes") %>'; 
    var downloadUrl = '<%= Url.Action("MemberDownloadNoteDocument", "AccessCodes") %>'; 

    $.ajax({ 
     url: url, 
     data: { RacodeID: racodeID }, 
     beforeSend: function() { 
      $('#listStatus').text('Updating List...'); 
     }, 
     complete: function() { 
      // $('#fileStatus').text('Request complete...'); 
     }, 
     dataType: 'json', 
     url: url, 
     async: false, 
     type: 'POST', 
     error: function (xhr, status, errorThrown) { 
      $('#listStatus').text('Sorry, there was a connection error: ' + xhr.status + '\n Please try again later.'); 
      console.log('There was a error: ' + xhr.status + ' - ' + xhr.responseText); 
      return errorThrown; 
     } 
    }) 
    .done(function (data) { 
     $('#list').show(); 
     $('.list-no-note').remove(); 

     if (data == '') { 
      $('#list').hide(); 
      $('#listContainer').append('<div class="list-no-note">There are no notes for this member. Use the "Add Member Note/Document" area to add your first note.</div>'); 
      $('.exportNotesLink').hide(); 
     } 
     else { 


      $.each(data, function (i, item) { 
       var followRequired = false; 
       var followUpBtn = ''; 
       var followUpInfo = ''; 
       var commentArea = ''; 

       if (item.followUpEmailSentOn != null) 
        followUpInfo = new Date(parseInt(item.followUpEmailSentOn.substr(6))); 

       var fulfilledBtn = '<span class="fulfill unfulfilled" >Fulfilled</span>'; 
       item.dateCreated = new Date(parseInt(item.dateCreated.substr(6))); 

       if (item.followUpDate != null) { 
        followRequired = true; 
        item.followUpDate = new Date(parseInt(item.followUpDate.substr(6))); 

       } else { item.followUpDate = "N/A"; } 

       if (item.isFulfilled) { 
        fulfilledBtn = '<span class="fulfill fulfilled" >Fulfilled</span>'; 
       } else { 
        fulfilledBtn = '<span class="fulfill unfulfilled" >UnFulfilled</span>'; 
       } 

       if (!item.followUpEmailSent && item.followUpDate != 'N/A' && !item.isFollowedUp) { 
        followUpBtn = '<img src="<%= ResolveUrl("~/Content/Images/Icons/followup_icon.png") %>" class="followUpBtn" title="A followup is scheduled for ' + item.followUpDate + '" />'; 
       } 

       if (item.followUpEmailSent && item.followUpDate != 'N/A' && item.followUpEmailSentOn != null) { 
        followUpInfo = '<img src="<%= ResolveUrl("~/Content/Images/Icons/checkmark.png") %>" height="20px" style="vertical-align:middle"/><span style="color:green">A Follow-up email was sent on ' + followUpInfo + ' to ' + item.followUpEmail + '</span>'; 

       } 

       if (item.comment != null && item.comment != '') { 
        commentArea = '<b>Comment:</b><span class="noteComment" > ' + item.comment + '</span><br /><br />'; 
       } 
       //console.log("inside loop..."); 
       var table; 
       var shortFileName; 
       var iconFile = ''; 
       var followupDate = ''; 

       if (item.fileName != '' && item.fileName != null && item.fileName.length > 25) 
        shortFileName = jQuery.trim(item.fileName).substring(0, 25).trim(this) + "..."; 
       else 
        shortFileName = item.fileName; 

       if (shortFileName != '' && shortFileName != null) { 
        iconFile = '<img src="<%= ResolveUrl("~/Content/Images/Icons/text_icon.png") %>" height="20px" title="Download this document" class="masterTooltip" style="vertical-align:middle"/>'; 
       } 

       if (item.followUpDate == null) 
        followupDate = 'N/A'; 
       else 
        followupDate = item.followUpDate; 


       var tr = (
       '<tr style="border-top:1px solid gray" class="table-row">' + 
       '<td class = "' + item.ID + '"> ' + fulfilledBtn + '</td>' + 
       '<td>&nbsp;</td>' + 
       '<td><span class="NoteDesc">' + item.description + '</span></td>' + 
       '<td>' + item.requestTakenBy + '</td>' + 
       '<td align="right"><a class="btnRemoveNote"><img class="' + item.ID + '" src="<%= ResolveUrl("~/Content/Images/Icons/delete-icon.png") %>" /></a></td>' + 
       '<td>&nbsp;</td>' + 
       '</tr>' + 
       '<tr class="table-row">' + 
       '<td colspan = "2" >' + followUpBtn + '</td>' + 
       '<td colspan="3" >' + commentArea + iconFile + '<a class="downloadUserFile"><span class="' + item.ID + '">' + shortFileName + '</span></a></td>' + 
       '<td></td>' + 
       '</tr><tr class="table-row">' + 
       '<td colspan="6" style="padding-left:30px;padding-right:20px;padding-bottom:10px;"><i><b>Follow-up Date:</b> ' + item.followUpDate + '</i></td></tr>' + 
       '</tr><tr class="table-row">' + 
       '<td colspan="6" style="padding-left:30px;padding-right:20px;padding-bottom:10px;">' + followUpInfo + '</td></tr>' + 
       '<script>$(".btnRemoveNote").confirm({msg: "Do you really want to remove this? "});<\/script>' 
        ); 

       $('#list').append(tr); 

      }); 
     } 
    }); 

    $('#listStatus').text(''); 
    console.log("Load List function complete..."); 
    return true; 
} 
+0

除非你使用插件,否則沒有jQuery確認方法。如果您使用的是插件,插件文檔將向您展示如何顯示它。檢查控制檯是否有錯誤 – charlietfl

+0

除了第一條評論的內容,請發佈你創建按鈕的方式,這可能是你的ajax調用檢查後的事件綁定問題[this](http://stackoverflow.com/questions/203198/)事件綁定動態創建元素) –

回答

0

只需使用JavaScript確認。

$('#list').on('click', '.btnRemoveNote', 
    function() {     
    confirm('Do you really want to remove this?'); 
    }      
); 

我覺得沒有$(本).confirm()在JQuery的,只是.dialog其中有多個參數。閱讀here。如果你願意,你可以使用它。

+0

我正在使用jquery.confirm.js插件。我想在這裏使用它,因爲我們在應用程序的其他幾個區域使用這個插件。沒有錯誤產生,記錄被簡單地刪除沒有任何確認。 – user2751629

相關問題