如何停止JS和HTML中的表单自动重置? [英] How to stop form auto-reset in JS and HTML?
本文介绍了如何停止JS和HTML中的表单自动重置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表单定义如下:
<form id="form" onsubmit="validate()">
我处理信息,然后按如下所示修改HTML的正文:
I process information and then modify the body of the HTML as follows:
var toRemove = document.getElementById("formContainer");
toRemove.parentNode.removeChild(toRemove);
document.getElementById("main").childNodes[1].innerHTML = text1;
document.getElementById("main").childNodes[3].innerHTML = text2;
这可能会显示一毫秒,但随后页面将重置为空白表格.我可以通过在以后添加警报来解决此问题,但是一旦我关闭警报,页面就会重置.有没有办法阻止它重置?
This displays corectly for a milisecond maybe, but then the page resets to the blank form. I can fix this by adding an alert afterwards, but as soon as I dismiss the alert the page resets. Is there a way to stop it from resetting?
这是完整的代码:
HTML- http://puu.sh/p7HIl/e1abcc7920.html JavaScript- http://puu.sh/p7HJ3/54850f8588.js
HTML - http://puu.sh/p7HIl/e1abcc7920.html JavaScript - http://puu.sh/p7HJ3/54850f8588.js
查看全文