【问题标题】:Javascript confirm box, yes/no, it shows confirm box but never waits for the use to hit Yes. it automatically submits the formJavascript 确认框,是/否,它显示确认框但从不等待用户点击是。它会自动提交表单
【发布时间】:2013-10-02 19:14:14
【问题描述】:

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 &lt; s10.value) 然后显示确认框说“Out Time 小于 In Time。可以吗??”

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

否则提交表单。

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

请帮忙。提前致谢。

【问题讨论】:

  • 如果您正确缩进代码并告诉我们s**.value 的所有内容是什么,也许我们可以提供帮助?
  • 你是如何运行这段代码的?
  • 如果它是从表单的 submit 处理程序运行的,您需要从该处理程序返回 false 以防止默认表单提交,并将您的 Yes 代码放在模态调用 form.submit() 中。

标签: javascript


【解决方案1】:

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

 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");

【讨论】:

  • s10.value --> Patient In Time s12.value --> Patient Out time s14.value --> 手术时间(在 Patient In Time 和 Out time 之间)示例:如果 Patient IN 时间--> 22:00 出诊时间:5:00 然后手术时间应在 22:00 到 5:00 之间,如 3:00
猜你喜欢
  • 1970-01-01
  • 2017-10-02
  • 2014-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-10
相关资源
最近更新 更多