gpt4 book ai didi

javascript - 测试时 jquery 无法在本地运行

转载 作者:行者123 更新时间:2023-12-02 14:32:39 25 4
gpt4 key购买 nike

我想在对话框上显示消息一段时间后重定向到新网页。我的代码无法正常工作,请纠正我。当我在本地运行时看不到对话框。

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>

最佳答案

您需要包含 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>

关于javascript - 测试时 jquery 无法在本地运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37710034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com