javascript - 点击后表单不消失
问题描述
我正在尝试创建一个登录表单,当用户单击登录按钮时该表单会出现和消失。下面的代码确保表单在开始时不显示,仅在用户单击时显示表单。但是,尽管第二次单击该按钮,表单并没有消失。我还包括下面的 jquery 字符串。我错过了什么还是因为 jquery 代码已经过时了?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
$(document).ready(function() {
const arrow = $(".arrow-up");
const form = $(".login-form");
const status = false;
$("#login").click(function(event) {
event.preventDefault();
if (status == false) {
arrow.fadeIn();
form.fadeIn();
status == true;
} else {
arrow.fadeOut();
form.fadeOut();
status = false;
}
})
})
.arrow-up {
width: 0;
height: 0;
position: absolute;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 20px solid #e86b00;
right: 750px;
bottom: 10px;
display: none;
}
.login-form {
position: absolute;
width: 300px;
height: auto;
background: #e86b00;
top: 20px;
right: -150px;
border-radius: 3px;
border-bottom: 5px solid gray;
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<li><a href="#" id="login">LogIn</a></li>
<div class="arrow-up">
<div class="login-form">
<form>
<div>
<label style="color:black">Username:</label>
<input type="text" placeholder="Username" id="usernm" autocomplete="new-password" required/>
</div>
<div>
<label style="color:black">Password:</label>
<input type="password" placeholder="Password" id="passw" autocomplete="new-password" required/>
</div>
<div>
<input type="submit" />
</div>
<div>
<a href="#">Lost Your Password</a>
</div>
</form>
</div>
</div>
解决方案
status == true;
应该status=true
推荐阅读
- html - 微软边缘浏览器中的材料 UI 可见性密码出现问题检查了不同的方法
- grep - 如何从两个列表中删除列表中的目录?
- terraform - 如何将地形变量转换为二头肌兼容的参数/变量
- sql - 最后一行的 SQL 组和条件总和
- ansible - Ansible:比较字典并创建一个带有结果的新字典
- sql - 春季批处理中不支持查询计数会引发异常错误
- android - CropImageActivity - 在 Redmi 6A (Android 8.1.0) 上点击 CROP(应用程序崩溃)并在 Galaxy M30 (Android 10) 上运行
- sql - COUNT 和 COUNT 的 ROLLUP SUM
- python - 找不到 Selenium 的按钮
- angular - Angular - 在客户刷新页面或清理缓存之前,不会在生产中显示更改