admin管理员组文章数量:1293159
Hi i have the following code:
<a onclick="show_login()">Login
<span id="login" style="visibility: hidden">
<form method="post" action="login.php">
<label for="username">Username:</label>
<input type="text" name="username" /></a>
<label for="password">Password:</label>
<input type="password" name="password" />
<input type="submit" name="login" value="Login" />
</form>
</span>
I want to know how to hide/show that span using the function name "show_login". How would i go about doing this?
Hi i have the following code:
<a onclick="show_login()">Login
<span id="login" style="visibility: hidden">
<form method="post" action="login.php">
<label for="username">Username:</label>
<input type="text" name="username" /></a>
<label for="password">Password:</label>
<input type="password" name="password" />
<input type="submit" name="login" value="Login" />
</form>
</span>
I want to know how to hide/show that span using the function name "show_login". How would i go about doing this?
Share Improve this question edited Aug 20, 2011 at 2:58 emboss 39.7k7 gold badges102 silver badges109 bronze badges asked Aug 20, 2011 at 2:53 Duncan PalmerDuncan Palmer 731 gold badge1 silver badge5 bronze badges 1-
You have some mismatched tags; the
a
tag ends inside of thespan
(and thespan
tag started in thea
tag). You might get some unexpected behavior unless your tags are matched. – icktoofay Commented Aug 20, 2011 at 2:55
2 Answers
Reset to default 5You probably shouldn't be using a <span>
for that, <div>
would serve you better. And visibility
probably isn't what you want either, visible: hidden
:
hidden
The generated box is invisible (fully transparent, nothing is drawn), but still affects layout. Furthermore, descendants of the element will be visible if they have 'visibility: visible'.
And you should close your <a>
before the login form.
You probably want to use display: none
and display: block
. So something like this:
<a onclick="toggle_login()">Login</a>
<div id="login" style="display: none">
<form method="post" action="login.php">
<label for="username">Username:</label>
<input type="text" name="username" /></a>
<label for="password">Password:</label>
<input type="password" name="password" />
<input type="submit" name="login" value="Login" />
</form>
</div>
And:
function toggle_login() {
var div = document.getElementById('login');
div.style.display = div.style.display == 'none' ? 'block' : 'none';
return false;
}
Live example: http://jsfiddle/ambiguous/6ngnU/1/
Set the style to display: none to start with and use the jquery function show to make it appear when you want it.
http://api.jquery./show/
本文标签: javascriptJava script function to hide a ltspangtStack Overflow
版权声明:本文标题:javascript - Java script function to hide a <span>? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741568908a2385888.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论