2014-10-30 59 views
0

我得到了我的代碼有問題:如何在打開對話框後停止代碼?

 $("#lbCreer").click(function (e) { 
      e.preventDefault(); 
      $("input:checked").each(function() { 
       var id = this.value; 
       $("#hdId").val(id); 
       $("#dialog-form").dialog("open"); 
      }); 
      alert('toto'); 
     }); 

我想打開對話框後,停止各。我不能這樣做?

感謝

+0

你可以'對話框打開跳出循環後返回FALSE',但爲什麼,如果你想打開對話框後,打破了你需要一個循環? – 2014-10-30 19:47:48

+0

我打開對話框,然後用戶確認服裝和當用戶點擊確定按鈕,我做了一個過程。我想爲所有的複選框做好準備。我不知道我的英語 – Eric 2014-10-30 19:58:32

回答

0

你需要排序的執行,但你不能使用循環做到這一點。看下面的例子來了解如何排序。

var $dialog; 
 
$(function() { 
 
    $dialog = $("#dialog").dialog({ 
 
    autoOpen: false, 
 
    buttons: [{ 
 
     text: "OK", 
 
     click: function() { 
 
     if ($selectedCheckboxes != null && $selectedCheckboxes.length > 1) { 
 
      $selectedCheckboxes = $selectedCheckboxes.slice(1); 
 
      updateDialog(); 
 
     } else { 
 
      $message.text('Processing complete, dialog will close in 5 seconds'); 
 
      setTimeout(function() { 
 
      $dialog.dialog("close"); 
 
      }, 5000); 
 
     } 
 
     } 
 
    }] 
 
    }); 
 

 
    var $message = $('#dialog .message'); 
 

 
    function updateDialog() { 
 
    $message.text('processing ' + $selectedCheckboxes.get(0).value + ' now, click Ok to start next'); 
 
    } 
 

 
    var $selectedCheckboxes = null; 
 
    $('#button').click(function() { 
 
    $selectedCheckboxes = $('input:checked'); 
 
    $dialog.dialog('open'); 
 
    updateDialog(); 
 
    }); 
 
});
.ui-widget { 
 
    font-size: 0.8em !important; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script> 
 
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.10.4/themes/black-tie/jquery-ui.css" media="screen, print" /> 
 
<label> 
 
    <input type="checkbox" value="Red" checked="checked" />Red</label> 
 
<label> 
 
    <input type="checkbox" value="Green" checked="checked" />Green</label> 
 
<label> 
 
    <input type="checkbox" value="Blue" checked="checked" />Blue</label> 
 
<label> 
 
    <input type="checkbox" value="Black" />Black</label> 
 
<label> 
 
    <input type="checkbox" value="White" />White</label> 
 
<button id="button">Check</button> 
 
<div id="dialog" title="My Dialog"><span class="message">Loading, please wait...</span> 
 
</div>

+0

我會嘗試你的序列 – Eric 2014-10-30 20:40:12

+0

它的效果很好。 Thans爲您提供幫助 – Eric 2014-10-31 08:47:17

+0

@Eric歡迎來到Stackoverflow。關閉,請接受它作爲答案,如果它爲你工作。 – 2014-10-31 13:45:23

0

這裏是所有代碼:

 $(document).ready(function() { 

     $("#dialog-form").dialog({ 
      autoOpen: false, 
      closeOnEscape: false, 
      draggable: true, 
      height: 'auto', 
      width: 'auto', 
      modal: true, 
      buttons: { 
       "Ok": function() { 
        var fok = $('#montantrecu').validationEngine('validate'); 
        if (!fok) { 
         $(this).dialog("close"); 
         $.ajax({ 
          type: "POST", 
          url: '<%=ResolveUrl("~/Services/Services.asmx/Facture")%>', 
          data: "{'IdMembre':'" + $('#hdId').val() + "', MontantFacture': '" + $('#montantrecu').text + "' }", 
          contentType: "application/json; charset=utf-8", 
          dataType: "json", 
          async: false, 
          success: function (response) { 
           alert("Ok"); 
          }, 
          failure: function (response) { 
           alert("failure"); 
          }, 
          error: function (request, status, error) { 
           alert(request.responseText); 
          } 
         }); 
        } 
       }, 
       "Annuler": function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 
     $("#lbCreer").click(function (e) { 
      e.preventDefault(); 
      $("input:checked").each(function() { 
       var id = this.value; 
       $("#hdId").val(id); 

       $.ajax({ 
        type: "POST", 
        contentType: "application/json; charset=utf-8", 
        url: '<%=ResolveUrl("~/Services/Services.asmx/GetNomPrenom")%>', 
        data: "{'IdMembre':'" + id + "'}", 
        dataType: "json", 
        async: false, 
        success: function (response) { 
         $("#liNom").text(response.d); 
        }, 
        failure: function (response) { 
         alert("failure"); 
        }, 
        error: function (request, status, error) { 
         alert(request.responseText); 
        } 
       }); 

       $.ajax({ 
        type: "POST", 
        contentType: "application/json; charset=utf-8", 
        url: '<%=ResolveUrl("~/Services/Services.asmx/GetMontantCotisation")%>', 
        data: "{'IdMembre':'" + id + "'}", 
        dataType: "json", 
        async: false, 
        success: function (response) { 
         $("#montantrecu").val(response.d); 
        }, 
        failure: function (response) { 
         alert("failure"); 
        }, 
        error: function (request, status, error) { 
         alert(request.responseText); 
        } 
       }); 
       $("#dialog-form").dialog("open"); 
      }); 
      alert('toto'); 
     }); 
    });