【发布时间】:2015-03-10 01:00:08
【问题描述】:
我在一个 html 页面上有两个表单 登录表单和注册表单
当我点击相应的“span”按钮时,我希望能够在表单之间切换
页面加载时应该只显示登录表单,但顶部的登录和注册“span”按钮
当我点击登录时,我希望登录表单“隐藏”并显示注册表单,反之亦然。
这是我目前的代码:
<!DOCTYPE html>
<head>
<title>Login Form</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<span href="#" class="btn btn-default" id="toggle-login">Log in</span>
<span href="#" class="btn btn-default" id="toggle-register">Register</span>
<div id="loginForm">
<form id='login' action='' method='post' accept-charset='UTF-8'>
<fieldset>
<legend>Log In</legend>
<p><input type="text" name="login" value="" placeholder="studentID"></p>
<p><input type="password" name="password" value="" placeholder="Password"></p>
<p class="submit"><input type="submit" name="commit" value="Login"></p>
</fieldset>
</form>
</div>
<div id="registerForm">
<form id='register' action='' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Register</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<p><label for='username' >UserName*:</label> <input type='text' name='username' id='username' maxlength="50" /></p>
<p><label for='name'>First Name*: </label> <input type='text' name='name' id='firstName' maxlength="50" /></p>
<p><label for='name'>Second Name*: </label> <input type='text' name='name' id='secondNname' maxlength="50" /></p>
<p><label for='email' >Email Address*:</label> <input type='text' name='email' id='email' maxlength="50" /></p>
<p><label for='password' >Password*:</label> <input type='password' name='password' id='password' maxlength="50" /></p>
<input type='submit' name='Submit' value='Submit' />
</fieldset>
</form>
</div>
<script>
</script>
</body>
</html>
谢谢!
【问题讨论】:
-
使用
visibility,一个CSS属性,交替显示/隐藏div
标签: javascript php jquery html ajax