【发布时间】:2019-02-10 18:58:16
【问题描述】:
我正在使用 jQuery UI 对话框。此处的代码使单击 HTML 按钮时弹出对话框。
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#dialog" ).dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
$( "#opener" ).on( "click", function() {
$( "#dialog" ).dialog( "open" );
});
} );
</script>
</head>
<body>
<div id="dialog" title="Basic dialog">
<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<button id="opener">Open Dialog</button>
</body>
</html>
这很好用,但我在这里有一个 if else 函数:
if(form.pswrd.value === "password")
{
window.open('page.html')/*opens the target page while Id & password matches*/
}
else
{
//jQuery Dialog opens HERE
}
}
底部的else 函数是我想要触发jQuery UI 对话框的地方。如何让else 打开 jQuery 对话框?我已经尝试过将这部分脚本包含在我的else 中,但无济于事:
$( "#opener" ).on( "click", function() {
$( "#dialog" ).dialog( "open" );
});
} );
【问题讨论】:
标签: javascript jquery html css jquery-ui