我希望当用户点击“没有账户?”一行时,能够触发
这些CSS中的
.registrybox
类的显示。我已经编写了一些脚本,但它并没有起作用。脚本指定当“没有账户?”被点击时,.loginbox
应该消失,并被.registrybox
类代码替换。这些CSS中的
display:none
和display:block
是预先编写好的。
function displayRegistry() {
document.getElementsByClassName('.registrybox').style.display = "block";
document.getElementsByClassName('.loginbox').style.display = "none";
}
.loginbox {
width: 320px;
height: 420px;
background-color: ;
color: #fff;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%, -50%);
padding: 50px 20px;
display: block;
}
}
h1 {
margin: 0;
padding: 0 0 20px;
text-align: center;
font-size: 22px;
}
.loginbox p {
margin: 0;
padding: 0;
font-weight: bold;
}
.loginbox input {
width: 100%;
margin-bottom: 20px;
}
.loginbox input[type="text"],
[type="password"] {
border: none;
border-bottom: 1px solid #fff;
outline: none;
background: transparent;
height: 40px;
color: #fff;
font-size: 16px;
}
.loginbox input[type="submit"] {
border: none;
outline: 0;
height: 40px;
background: #fb2525;
color: #fff;
font-size: 18px;
border-radius: 20px;
}
.loginbox input[type="submit"]:hover {
cursor: pointer;
background: red;
color: #000;
}
.loginbox a {
text-decoration: none;
color: darkgrey;
font-size: 15px;
line-height: 20px;
}
.loginbox a:hover {
color: red;
}
.registrybox {
width: 320px;
height: 420px;
color: #fff;
top: 10%;
left: 20%;
position: absolute;
transform: trnaslate(-50%, -50%);
}
.registrybox p {
font-weight: bold;
margin: 0;
padding: 0;
}
.registrybox input {
width: 100%;
margin-bottom: 20px;
}
.registrybox input[type="text"],
[type="password"] {
border: none;
border-bottom: 1px solid #fff;
outline: none;
background: transparent;
height: 40px;
color: #fff;
font-size: 16px;
}
.registrybox input[type="submit"] {
border: none;
outline: 0;
height: 40px;
color: #fff;
background: #fb2525;
font-size: 18px;
border-radius: 20px;
}
.registrybox input[type="submit"]:hover {
cursor: pointer;
background: red;
color: #000;
}
.registrybox a {
text-decoration: none;
color: darkgrey;
line-height: 20px;
font-size: 15px;
}
.registrybox {
display: none;
}
select {
padding: 10px;
border: none;
border-radius: 10px;
}
<div class="loginbox">
<h1>Login Here</h1>
<form>
<p>Username</p>
<input type="text" name="" placeholder="Enter Username">
<p>Password</p>
<input type="password" name="" placeholder="Enter Password">
<input type="submit" name="" value="Login">
<a href="#">Forgot password?</a><br>
<a href="#" onclick="displayRegistry()">Dont have an account?</a>
</form>
</div>
<div class="registrybox">
<h1>Registration</h1>
<form>
<p>Username</p>
<input type="text" placeholder="Enter Username">
<p>E-mail</p>
<input type="text" placeholder="Enter E-mail">
<p>Password</p>
<input type="password" placeholder="Enter password">
<p>Repeat Password</p>
<input type="password" placeholder="Confirm password">
<input type="submit" value="Sign up">
<a hred="#">Already registered?</a>
<select name="dobmonth">
<option>month</option>
<option value="january">January</option>
</select>
<select name="dobyear">
<option>Year</option>
<option value="2000">2006</option>
<option value="2000">2005</option>
<option value="2000">2004</option>
<option value="2000">2003</option>
<option value="2000">2002</option>
<option value="2000">2001</option>
<option value="2000">2000</option>
<option value="2000">1999</option>
</select>
</form>
</div>
displayLogin
的函数,并将onclick="displayLogin()
代码添加到“已注册”行。只是重新使用了我为displayRegistry
编写的代码,但效果相反(注册表单消失并被登录表单替换)。 - Alexander