单击“发送”按钮时alert()起作用,但对话框从不显示。我一直在疯狂试图找出原因。我究竟做错了什么?请参见下面的代码:
谢谢, TD
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
<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
function msg(){
$("#dialog_login").text('Login Successful');
$("#dialog_login").dialog('open');
alert('Login Successful');
}
function loadMsg(){
$("#dg").load("form.html");
}
答案 0 :(得分:0)
嗨,我更改了一些代码,希望这对您有用
function msg(){
$("#dialog_text").text('Login Successful');
$("#dialog_login").dialog({
show: { effect: "blind", duration: 800 }
})
};
还有其他错误
<div class="form-group">
<input type="submit" name="submit" value="Send" id="submit" class="btn btn-primary">
</div
使用“>”
关闭div <div class="form-group">
<input type="submit" name="submit" value="Send" id="submit" class="btn btn-primary">
</div>
答案 1 :(得分:0)
好吧,经过数小时的研究,我发现了问题;我已经在ID中添加了“#”:
<div id="#dialog_login" title="Login Status">
我纠正了这个问题:
<div id="dialog_login" title="Login Status">
接下来,我将这一行添加到dg.js:
$('#dialog_login').dialog({autoOpen: false});
所以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");
我要感谢所有尝试提供帮助的人!