gpt4 book ai didi

javascript - 警报按钮没有响应

转载 作者:行者123 更新时间:2023-11-28 19:04:47 25 4
gpt4 key购买 nike

这是我的代码:

<!DOCTYPE html>
<html>
<head>
<title>Project 506</title>
<link rel="stylesheet" href="" type="text/css" />
<script type="text/javascript" src="sweetalert.min.js"></script>
<style type="text/css">
body {
text-align: center;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
$("#first").click(function () {
alert("Oops...", "Something went wrong!", "error");
});
});
</script>
</head>
<body>
<h1>Message Boxes</h1>
<input type="button" id="first" value="Just a Notification" />
<input type="button" id="second" value="Successfully Completed!" />
<input type="button" id="third" value="Something Went Wrong!" />
</body>
</html>

点击#first后如何显示警告框?我不确定这段代码有什么问题。

感谢您的帮助。

最佳答案

您忘记在代码中添加 jquery 库。您需要将 jquery 脚本包含在代码的 head 或 body 中,以使代码正常工作。

Jquery

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

alert() 函数中只允许使用一个参数。如果您使用多个参数,则将使用逗号之前的第一个参数。

这是你的代码

alert("Oops...", "Something went wrong!", "error"); //this will alert oops..

更新了代码

alert("Oops...Something went wrong! error");

我看到你在代码中使用了可爱的alert.js。如果您想要 sweetalert 而不是 native 警报框。您需要使用以下代码替换您的代码。甜蜜警报中允许使用逗号

sweetAlert("Oops...", "Something went wrong!", "error");

查看更新后的代码:) :)

<!DOCTYPE html>
<html>
<head>
<title>Project 506</title>
<link rel="stylesheet" href="" type="text/css" />

<script type="text/javascript" src="sweetalert.min.js"></script>
<style type="text/css">
body {
text-align: center;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
$("#first").click(function () {
alert("Oops...Something went wrong! error");
});
});
</script>
</head>
<body>
<h1>Message Boxes</h1>
<input type="button" id="first" value="Just a Notification" />
<input type="button" id="second" value="Successfully Completed!" />
<input type="button" id="third" value="Something Went Wrong!" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</body>
</html>

查看 js fiddle JSFIDDLE

关于javascript - 警报按钮没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31902070/

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