【问题标题】:Jquery modal window is not working for multiple eventsJquery模式窗口不适用于多个事件
【发布时间】:2014-05-02 21:14:05
【问题描述】:

我想完成等待窗口,为此我采取了jquery模态对话框。

在一种情况下,在tab->需要检查记录是否存在。

在这种情况下,模式工作得非常好,也可以尝试几次。

但是如果我想为不同的事件打开相同的模式,它就不起作用了。

例如,在我的页面中,用户可以动态添加项目,最终用户需要将所有这些项目提交给数据库。

对于这个提交,我需要打开相同的模式,但它不起作用。

这是我的代码:

ready() 内,我正在调用对话框:

function WaitingWindows() {
    $("#test").dialog({
        autoOpen: false,
        modal: true,
        zIndex: 3999,
        disabled: false,
        closeOnEscape: false,
        beforeclose: function (event, ui) { return false; },
        dialogClass: "noclose",
        draggable: false,
        resizable: false,
        position: ['center', 'center'],
        open: function (event, ui) {
            $('.ui-widg`enter code here`et-content').css('background', 'none');
            $('.ui-widget-content').css('border', 'none');
            $('.ui-widget-header').css('background', 'none');
            $('.ui-widget-header').css('border', 'none');
            $('.ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close').remove();

        }
    });
}

模态分区:

 <%--loading Image--%>
        <div id="test" style="float:left;width:100px;height:100px;">
        <div style="float:left;width:100px;">
            <img   id="loading" src="Resources/Image/waiting.gif" />

        </div>
        <br />
         <div style="float:left;width:63px;font-size:medium;font-weight: bold;color:#787878 ;">
             Loading...
         </div>

        </div>

 <%--loading Image end--%>

对话框打开和关闭:

 $("#test").dialog("open");$("#test").dialog("close");

第一种方法(工作正常):

 $("#txt_orderNo").blur(function () {$("#test").dialog("open");}

第二种方法(不工作):

 $('#btn_us_submit').click(function () {$("#test").dialog("open");}

我也用过:

$("#btn_us_submit").on('click', function (e) {}

但打不开。

【问题讨论】:

  • 您检查浏览器控制台是否有任何错误?

标签: jquery json modal-dialog


【解决方案1】:

你可以在ready()函数中使用吗

$("#txt_orderNo").blur(function () {$("#test").dialog("open");} )};

我觉得应该可以了。

【讨论】:

  • 我使用 ready() 函数初始化对话框并使用 $("#txt_orderNo").blur(function () {} 打开对话框..它在这种情况下工作正常但不起作用如果我想为其他函数打开相同的对话框。例如 $('#btn_us_submit').click(function () {$("#test").dialog("open");}
  • 我指出了拉维什的回答。他在回答中关闭了额外的},尽管他建议写在document.ready(),但他必须把整个结构放在这里,在@RajaAshutoshNayak 你的情况下你能创建JSFidle吗?
  • 杰瑞是对的,对不起。实际语法是 $("#txt_orderNo").blur(function () {$("#test").dialog("open");});你也可以试试这个。
  • @Ravish Patel:我需要通过一些额外的操作打开按钮点击事件中的对话框。
  • @Ravish Patel:根据您的建议,我在按钮单击侧调用了 ShowPopUp() 仍然有同样的问题。一些控件是动态生成的,有些是静态的。此模式工作的 Blurb() 是一个静态控件,然后是一些动态 div 和控件,然后是提交按钮,这也是一个静态控件。
【解决方案2】:

我认为它可以帮助你

function ShowPopUp()
{
    $("#test").dialog().dialog('open');
    $("#test").dialog({ autoOpen: false,
        modal: true,
        zIndex: 3999,
        disabled: false,
        closeOnEscape: false,
        beforeclose: function (event, ui) { return false; },
        dialogClass: "noclose",
        draggable: false,
        resizable: false,
        position: ['center', 'center'],
        open: function (event, ui) {
            $('.ui-widg`enter code here`et-content').css('background', 'none');
            $('.ui-widget-content').css('border', 'none');
            $('.ui-widget-header').css('background', 'none');
            $('.ui-widget-header').css('border', 'none');
            $('.ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close').remove();

             }
        });
}

【讨论】:

  • @Ravish Patel:我在创建模式时没有任何问题,它仅适用于 .blurb() 方法绝对可以正常工作。如果我想将其用于其他事件,如 $(' #btn_us_submit').click(function () {$("#test").dialog("open");} 它不起作用
  • 为什么不能像这样在按钮点击事件上直接调用 WaitingWindows() 的函数 $("#btn_us_submit").click(function() { WaitingWindows() });请检查它是否有效并解决您的问题。
  • @Ravish Patel:根据您的建议,我在按钮单击侧调用了 ShowPopUp() 仍然有同样的问题。一些控件是动态生成的,有些是静态的。此模式工作的 Blurb() 是一个静态控件,然后是一些动态 div 和控件,然后是提交按钮,这也是一个静态控件。
猜你喜欢
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-06
  • 2022-11-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多