尝试从登录表单和注册表单切换。不断从Javascript获得错误:
未捕获类型错误:无法读取未定义的属性(正在读取"样式"(
不确定根据此错误还可以查看哪些内容。已经尝试过将JS作为.JS文件,同样的问题。
代码:
<div class="col-2">
<div class="form-container">
<div class="form-btn">
<span onclick="login()"> Login </span>
<span onclick="register()">Register</span>
<hr id="Indicator">
</div>
<form id="LoginForm">
<input type="text" placeholder="Username">
<input type="password" placeholder="Password">
<button type="submit" class="btn">Login</button>
<a href="">Forgot Password</a>
</form>
<form id="RegForm">
<input type="text" placeholder="Username">
<input type="email" placeholder="Email">
<input type="password" placeholder="Password">
<button type="submit" `enter code class="btn">Register</button>
</form>
<script>
var LoginForm = document.getElementbyID("LoginForm");
var RegForm = document.getElementbyID("RegForm");
var Indicator = document.getElementById("Indicator");
function register() {
LoginForm.style.transform = "translateX(0px)";
RegForm.style.transform = "translateX(0px)";
Indicator.style.transform = "translateX(100px)";
}
function login() {
LoginForm.style.transform = "translateX(300px)";
RegForm.style.transform = "translateX(300px)";
Indicator.style.transform = "translateX(0px)";
}
</script>
var LoginForm = document.getElementbyID("LoginForm");
var RegForm = document.getElementbyID("RegForm");
var Indicator = document.getElementById("Indicator");
你的选择器有打字错误。应该是
document.getElementById(id);