我想在对话框上显示一段时间的消息后重定向到新的网页。 我的代码无效,请指正。我在本地运行时看不到对话框。
的test.html
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
if ($("#alert").length) {
var title;
if ($("#alert span").length) {
title = $("#alert span").text();
}
$("#alert div").dialog({
title: title,
modal: true,
open: function() { var foo = $(this);
setTimeout(function() {
foo.dialog('close');
}, 2000);
window.location.href = "http://stackoverflow.com";
}
});
}
});
</script>
<body>
<div id="alert">
<span>Password change</span>
<div>Password was successfully changed.</div>
</div>
</body>
<html>
答案 0 :(得分:2)
您需要包含jQuery-UI才能使用对话框功能。
$(document).ready(function() {
if ($("#alert").length) {
var title;
if ($("#alert span").length) {
title = $("#alert span").text();
}
$("#alert div").dialog({
title: title,
modal: true,
open: function() {
var foo = $(this);
setTimeout(function() {
foo.dialog('close');
}, 2000);
//window.location.href = "http://stackoverflow.com";
}
});
}
});
<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
</head>
<body>
<div id="alert">
<span>Password change</span>
<div>Password was successfully changed.</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<!- I've added this. ->
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
</body>
<html>
答案 1 :(得分:0)
确保您托管html文件和所有本地localhost。
也许使用nodejs甚至使用IIS来托管它们,然后从那里打开文件。