【发布时间】:2017-08-23 07:21:11
【问题描述】:
当我点击 div 外部时,我想关闭 login-content div 我尝试了事件但它不起作用
我有这个 html 代码
<nav class="login">
<ul>
<li id="login">
<a id="login-trigger" href="#">
Log in <span>▼</span>
</a>
<div id="login-content">
<form>
<fieldset id="inputs">
<input id="username" type="text" name="uname"
placeholder="University ID" required>
<input id="password" type="password" name="Password"
placeholder="Password" required>
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit" value="Log in">
<label><input type="checkbox" checked="checked"> Keep me signed
in</label>
</fieldset>
</form>
</div>
</li>
</ul>
这个js文件script.js
$(document).ready(function(){
$('#login-trigger').click(function(){
$(this).next('#login-content').slideToggle();
$(this).toggleClass('active');
if ($(this).hasClass('active')) $(this).find('span').html('▲')
else $(this).find('span').html('▼')
})
});
【问题讨论】:
-
请提供一些更完整的代码
-
您需要删除登录内容吗?或者只是隐藏它?
标签: javascript jquery html