如何在打开对话框后停止代码?

时间:2014-10-30 19:46:42

标签: jquery modal-dialog each

我的代码出了问题:

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

打开对话框后我想停止每个。我怎么做不到?

由于

2 个答案:

答案 0 :(得分: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');
        });
    });

答案 1 :(得分: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>