gpt4 book ai didi

javascript - 使用 JavaScript 从页面中删除 div

转载 作者:太空宇宙 更新时间:2023-11-03 19:36:54 27 4
gpt4 key购买 nike

一旦收到 XMPHttpRequest 响应,我将尝试从我的页面中删除一个 div。我还尝试使用以下方法将 div 的显示设置为无:document.getElementById('password').style.display = 'none';但这也不起作用。

HTML:

 <div class="login-container">
<div class="title">Login Form</div>
<div class="form-fields" id="form-fields">
<form name="login_form" method="post" id="login-form" onsubmit="return submitForm()">
<input type="text" name="username" id="username" placeholder="Username" required></input>
<input type="password" name="password" id="password" placeholder="Password" required></input>
<input type="submit" value="Log in" id="submit-button"></input>
<input id="sessionID" class="hidden"></input>
</form>
</div>
<div id="success-message" class="hidden">Congratulations! You have been logged in.</div>
<button id="logout" class="hidden"></button>
</div>

Javascript 函数:

 function sendLoginInfo() {
var loginRequest = new XMLHttpRequest();
loginRequest.open("POST", "server/login.php", false);
loginRequest.setRequestHeader('Content-type', "application/json");
loginRequest.onreadystatechange = function () {
if(loginRequest.readyState == 4 && loginRequest.status == 200) {
sessionID = keyRequest.responseText;
var el = document.getElementById( 'password' );
el.parentNode.removeChild( el );

}
}
loginRequest.send(JSON.stringify(JSONFormData));
}

更新

这个问题通过改变解决了:

<form name="login_form" method="post" id="login-form" onsubmit="return submitForm()">

收件人:

<form name="login_form" method="post" id="login-form" onsubmit="submitForm(); return false;">

最佳答案

代替

document.getElementById('password').style.display = 0;

尝试

document.getElementById('password').style.display = 'none';

关于javascript - 使用 JavaScript 从页面中删除 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26664441/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com