gpt4 book ai didi

Javascript 不适用于最大/最小按钮?

转载 作者:可可西里 更新时间:2023-11-01 00:40:02 25 4
gpt4 key购买 nike

我正在执行最大化/最小化按钮功能。我的 javascript 代码不工作。建议我任何解决方案。提前致谢。

这是我的代码

<html>
<head>
<script>
$(function () {
$(".button-open").hide();
$(".button-close").bind("click", function () {
$(".box").hide(100);

if ($(this).attr("class") == "button-close")
{
$(".button-open").show();
}
});
});

$(".button-open").bind("click", function () {
$(".box").show(100);
if ($(this).attr("class") == "button-open")
{
$(".button-open").hide();
}
});
</script>
</head>
<body>
<div class="button-open">Open</div>
<div class="box">
<div class="button-close">X</div>
</div>
</body>
</html>

最佳答案

在使用 JQuery 语法之前,请务必记住包含 JQuery 文件。如果您不想使用 JQuery,那么您需要编写纯 Javascript。但如果您只是在 HTML 中引用 JQuery,这对您来说将是一个简单的解决方法。

$(function () {
$(".box").hide();
$(".button-close").bind("click", function () {
$(".box").hide(100);

if ($(this).attr("class") == "button-close")
{
$(".button-open").show();
}
});
});

$(".button-open").bind("click", function () {
$(".box").show(100);
if ($(this).attr("class") == "button-open")
{
$(".button-open").hide();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="button-open">Open</div>
<div class="box">
<div class="button-close">X</div>

关于Javascript 不适用于最大/最小按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44859893/

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