表单提交上的Jquery Ui对话框

时间:2015-04-10 01:36:21

标签: jquery forms user-interface submit jquery-ui-dialog

我正试图阻止jquery ui对话框在表单提交满足1条件后弹出。我正在寻找每个事件一个对话框。如果满足条件,有点休息。目前所有对话框都在关闭后出现。我试过stopPropagation和stopImmediatePropagation没有任何效果。我的代码如下:

    $('#myForm').on('submit',function(e){
     if ($("#tramA").is(':checked') && !$('.tramAChecked:checked').length) {
                   $( "#tramA-message" ).dialog({
                    modal: true,
      draggable: false,
      resizable: false,
      buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
        }
      }
});
e.preventDefault();
}

     if ($("#tramB").is(':checked') && !$('.tramBChecked:checked').length) {
     $( "#tramB-message" ).dialog({
                    modal: true,
      draggable: false,
      resizable: false,
      buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
        }
      }
 });
e.preventDefault();
} 
});

HTML:

<div id="tramB-message" title="Warning">
  <p>
    <span class="ui-icon ui-icon-alert" style="float:left; margin:3px 7px 50px 0;"></span>
    You selected "Tram B hall" but did not select a tram option!
  </p>
  </div>
  <div id="tramA-message" title="Warning">
  <p>
    <span class="ui-icon ui-icon-alert" style="float:left; margin:3px 7px 50px 0;"></span>
    You selected "Tram A hall" but did not select a tram option!
  </p>
  </div>

1 个答案:

答案 0 :(得分:0)

更改e.preventDefault();返回虚假;做了伎俩。