简体   繁体   English

为什么对话框不显示?

[英]Why is the dialog not showing?

The alert() works when the Send button is clicked but the dialog never shows. 单击“发送”按钮时,alert()起作用,但对话框从不显示。 I have been going crazy trying to figure out why this is. 我一直在疯狂试图找出原因。 What am I doing wrong? 我究竟做错了什么? Please see code below: 请参见下面的代码:

Thanks, TD 谢谢,TD

index.html 的index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>DIALOG TEST</title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>   
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

</head>
<body onload="loadMsg()">

    <div id="dg"></div>

    <div id="#dialog_login" title="Login Status">
        <br />
        <div id="dialog_text" style="text-align: center;"></div>
    </div>

    <script type="text/javascript" src="dg.js"></script>
</body>
</html>

form.html form.html

    <div class="panel panel-default">
        <div class="panel-heading">TEST</div>
            <div class="panel-body">
                <form method="post" action="javascript:msg();">  
                    <div class="form-group">
                        <input type="submit" name="submit" value="Send" id="submit" class="btn btn-primary">
                    </div                       
                </form>   
            </div>
        </div>
    </div>

dg.js dg.js

function msg(){
    $("#dialog_login").text('Login Successful');
    $("#dialog_login").dialog('open');
    alert('Login Successful');  
}

function loadMsg(){
    $("#dg").load("form.html");
}

Hi I changed a little bit the code, I hope this works for you 嗨,我更改了一些代码,希望对您有用

function msg(){
$("#dialog_text").text('Login Successful');
$("#dialog_login").dialog({
    show: { effect: "blind", duration: 800 } 

  })
};

And you have other error 还有其他错误

 <div class="form-group">
                    <input type="submit" name="submit" value="Send" id="submit" class="btn btn-primary">
                </div    

close the div with ">" 用“>”关闭div

 <div class="form-group">
                    <input type="submit" name="submit" value="Send" id="submit" class="btn btn-primary">
                </div>    

OK, after many hours of looking at this I found the problem; 好吧,经过数小时的研究,我发现了问题; I had added '#' to the id: 我已经在ID中添加了“#”:

<div id="#dialog_login" title="Login Status">

I corrected this: 我更正了这一点:

 <div id="dialog_login" title="Login Status">

Next I added this line to dg.js: 接下来,我将此行添加到dg.js:

$('#dialog_login').dialog({autoOpen: false});

So dg.js looks like this now: 所以dg.js现在看起来像这样:

function msg(){
$('#dialog_login').dialog({autoOpen: false});
$("#dialog_login").text('Login Successful');
$("#dialog_login").dialog('open');
alert('Login Successful');  
}

function loadMsg(){
    $("#dg").load("form.html");

I want to thank everyone who tried to help! 我要感谢所有尝试提供帮助的人!

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

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