我想在表单提交后显示一条消息,并从页面中删除该表单。
脚本的第一部分正在工作,但第二部分(我试图删除表单)却无法工作。
有什么建议吗?
<script>
$(document).ready(function () {
if(window.location.href.indexOf("footer") > -1) {
document.getElementById("thanksForMessage").innerHTML = "<h2>Thanks for the message. I will contact you shortly.</h2>";
var formDiv = document.getElementById("formwell");
var childForm = document.getElementsByTagName("form");
formDiv.removeChild(childForm);
}
});
</script>发布于 2016-12-01 14:02:57
var childForm = document.getElementsByTagName("form");这将返回一个NodeList (就像一个数组),而不是一个元素。removeChild需要一个单一的元素。你只需通过第一个:
formDiv.removeChild(childForm[0]);发布于 2016-12-01 14:07:09
尝试使用类似这样的代码
$(document).ready(function () {
if(window.location.href.indexOf("footer") > -1) {
$("#thanksForMessage").html("<h2>Thanks for the message. I will contact you shortly.</h2>");
var formDiv = $("#formwell");
var childForm = "form";
formDiv.remove(childForm);
}});
https://stackoverflow.com/questions/40912604
复制相似问题