Javascript确认框,是/否,它显示确认框但从不等待使用命中是。它会自动提交表单

时间:2013-10-02 19:14:14

标签: javascript

Javascript代码:

   if (s12.value < s10.value) {
       $('<div></div>').appendTo('body')
           .html('<div><h6>' + "Out Time is less than In Time. Is that ok??" + '</h6></div>')
           .dialog({
               modal: true,
               title: 'Confirmation',
               zIndex: 10000,
               autoOpen: true,
               width: 'auto',
               resizable: true,
               buttons: {
                   Yes: function () {
                       if (s10.value < s14.value || s14.value < s12.value) {
                           alertDialog("Time is not between out time and in time.");
                       } else {
                           $("#<%=Button1.ClientID%>").submit();
                       }
                       $(this).dialog("close");
                   },
                   No: function () {
                       $(this).dialog("close");
                   }
               },
               close: function (event, ui) {
                   $(this).remove();
               }
           });

       < script >
           function alertDialog(message) {
               $('<div></div>').appendTo('body')
                   .html('<div><h6>' + message + '</h6></div>')
                   .dialog({
                       modal: true,
                       title: 'Errors',
                       zIndex: 10000,
                       autoOpen: true,
                       width: 'auto',
                       resizable: true,
                       buttons: {
                           Ok: function () {

                               $(this).dialog("close");
                           },

                       },
                       close: function (event, ui) {
                           $(this).remove();
                       }
                   });
       }; < /script>

条件1:if (s12.value < s10.value)然后显示确认框,说“出时间小于及时。可以吗?”

如果用户选择是,则选择条件2:if (s10.value < s14.value || s14.value < s12.value),然后显示警告框

否则提交表格。

问题:它能够显示确认框,但从不等待用户点击是/否,它会自动提交表单。

请帮助。提前致谢。

1 个答案:

答案 0 :(得分:0)

你应该创建一个没有打开的对话框

 var dialog_var = $('<div></div>').appendTo('body')
 .html('<div><h6>' + message + '</h6></div>')
 .dialog({
 modal: true, title: 'Errors', zIndex: 10000, autoOpen: true,
 width: 'auto', resizable: true,
 buttons: {
 Ok: function () {
   $(this).dialog("close");
 },


function alertDialog(message) {
  $(dialog_var).dialog("open");
相关问题