简体   繁体   English

弹出模态对话框

[英]Pop up Modal Dialog Box

Using this post I've been able to implement a dialog box that appears once the form is loaded. 使用这篇文章,我已经能够实现一个加载表单后出现的对话框。 I would however like to change this so that the user clicks a button for the dialog to appear. 但是,我想更改此设置,以便用户单击按钮以显示对话框。

I've followed the guidance provided, and removed this line $("#divdeps").dialog('open'); 我按照提供的指导,删除了这一行$("#divdeps").dialog('open'); from the Javascript function as instructed, and added it to the 'onclick' event of my button ie 从指示的Javascript函数,并将其添加到我的按钮的'onclick'事件,即

<button type="button" value="Upload" onclick="$('#divdeps').dialog('open');">Upload</button>

so my code is now: 所以我的代码现在是:

<div id="divdeps" style="display: none">This is my div</div>
<button type="button" value="Upload" onclick="$('#divdeps').dialog('open');">Upload</button>
<script> 
$(document).ready(function(){
  $("#divdeps").dialog({
    autoOpen: false,
    show: 'slide',
    resizable: false,
    position: 'center',
    stack: true,
    height: 'auto',
    width: 'auto',
    modal: true
  });

 // $("#divdeps").dialog('open');
});

</script>

However, I can't get this to work on the 'onclick' event of the button. 但是,我不能让它在按钮的'onclick'事件上工作。 I've been through the instructions quite a few times now and I'm not sure where I'm going wrong. 我现在已经完成了几次指示,我不确定我哪里出错了。

I just wondered whether someone could perhaps take a look at this please and let me know what I'm doing wrong. 我只是想知道是否有人可以看看这个,让我知道我做错了什么。

Many thanks and regards 非常感谢和问候

I would do it with the click function of jQuery instead of that dom level 0 handler: 我会用jQuery的click函数代替那个dom level 0 handler:

$("#divdeps + button").click(function() { $("#divdeps").dialog('open'); });

Or of course you can give this button an id and do 或者,当然,您可以给此按钮一个ID并执行

$("#buttonID").click(function() { $("#divdeps").dialog('open'); });

Either of those sections of code would go in your document.ready handler. 这些代码中的任何一个都将放在document.ready处理程序中。


Per Virendra's comment, your original button tag was wrong—you were missing a closing tag, and have mismatched quotes: 根据Virendra的评论,您原来的按钮标签是错误的-您缺少结束标签,并且引号不匹配:

<button value="Upload" onclick="$("#divdeps").dialog('open');"</button> 

should have been 本来应该

<button value="Upload" onclick="$('#divdeps').dialog('open');"> </button> 

Instead of $("#divdeps").dialog('open'); 代替$("#divdeps").dialog('open'); that you commented out, try: 你注释掉了,试试:

$("button#give_it_some_id").click(function(e) {
    e.preventDefault();
    $("#divdeps").dialog('open');
})

Use this code its working in my application. 使用此代码在我的应用程序中工作。

PopUpWindow = function (titles, message, redirectURL) {
        document.getElementById('window').innerHTML = message;
        $("#window").dialog({
            resizable: true,
            height: 180,
            title: titles,
            width: 500,
            modal: false,
            open: function () {
                $('.ui-widget-overlay').show();
                $('.ui-dialog-titlebar-close.ui-corner-all').hide();
            },
            buttons: {
                "OK": function () {
                    $(this).dialog("close");
                    if (redirectURL) {
                        window.location = redirectURL;
                    }
                }
            }
        });
    };

div tag div标签

  <div id="window" style="display: none;width:190px"> 

Let me know if you have any problem here. 如果您有任何问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM