removeChild not working
removeChild not working
大家好,当我点击一个按钮时,我正试图删除我的表单,但没有结果。我确信函数"sign()"被调用了,但对我的布局没有影响:
<body>
<div id="divSign">
<form action="#" method="post">
<div class="header">
<p>All Together</p>
</div>
<div class="description">
<p>Hi friend</p>
</div>
<div class="input">
<input type="text" class="button" id="chiave" placeholder="Chiave Segreta">
<input type="submit" class="button" id="submit" value="ENTRA" onclick="sign();">
</div>
</form>
</div>
</body>
<script>
function sign() {
document.body.removeChild(document.getElementById("divSign"));
// OR THIS
var f = document.getElementById("divSign");
while (f.hasChildNodes()) {
f.removeChild(f.lastChild);
}
// OR THIS
var f = document.getElementById("divSign").style.visibility = "hidden";
}
</script>
似乎没有什么影响我的页面,我只是在点击后清除我的页面。
点击后,您的表单将被提交,页面将刷新。
使用此onclick,return false;
将阻止表单提交,并且您的页面将不再刷新:
<input type="submit" class="button" id="submit" value="ENTRA" onclick="sign(); return false;">
它不会被删除,因为页面是在您单击按钮后重新加载的,因为它是一个表单。为了防止这种情况,您可以在函数末尾使用return false;
。
function sign() {
/*********
Your code
**********/
return false; //add this line
}
使用jquery可以使用空
$("#divSign").empty()
或
$("#divSign form").remove()
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working