【发布时间】:2017-12-05 04:57:42
【问题描述】:
我正在做最大化/最小化按钮功能。我的 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使用.toggle()之类的东西而不是交换会不会更容易类并绑定两个事件侦听器,您似乎也缺少类属性更改“假设您希望允许客户端在关闭时打开/显示该元素或在打开时关闭它”
标签: javascript php jquery html css