Keep getting Uncaught type error: cannot read properties of undefined (reading 'style') error is JS
Keep getting Uncaught type error: cannot read properties of undefined (reading 'style') error is JS
正在尝试从登录表单和注册表单切换。不断收到来自 Javascript 的错误:
Uncaught type error: cannot read properties of undefined (reading
'style')
根据这个错误不确定还要看什么。尝试将 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);
正在尝试从登录表单和注册表单切换。不断收到来自 Javascript 的错误:
Uncaught type error: cannot read properties of undefined (reading 'style')
根据这个错误不确定还要看什么。尝试将 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);