2016-12-19 6 views
0

Ich benutze bootbox Bibliothek. Ich habe einen Knopf mit dem Namen Delete.Modal ist es mehrmals geöffnet

$('body').on("click", ".deleteDiagnostic", function() { 
     var id = $(this).attr("data-diagnosticID"); 
     var currentRow = $(this).closest('tr'); 
     bootbox.confirm("Are you sure want to delete?", function (result) { 
      if (result == true) { 
       //code here 
      } 
     }); 
}); 

Ich verwende auch PartialView und die Seite, die Schaltfläche dynamisch geladen enthält wird. Manchmal, wenn ich klicke, ist die Bootbox mehrmals geöffnet und ich weiß nicht warum.

PS: Wenn ich PartialView für erstes Mal lade es funktioniert perfekt, aber wenn ich PartialView mehrere Male laden, dann bootbox mehrmals auf button Klick erscheint.

Antwort

1

Bitte versuchen Sie Ihren Code wie folgt zu ändern:

$('body').on("click", ".deleteDiagnostic", function (evt) { 
    evt.stopImmediatePropagation(); 

    var id = $(this).attr("data-diagnosticID"); 
    var currentRow = $(this).closest('tr'); 
    bootbox.confirm("Are you sure want to delete?", function (result) { 
     if (result == true) { 
      //code here 
     } 
    }); 
}); 
+0

Ja, das funktioniert. Vielen Dank . –

+0

Sehr erfreut! :) –

Verwandte Themen