表单提交后怎么样才能不清空文本框和下拉框的值呢?

表单提交后怎么样才能不清空文本框和下拉框的值呢?

submit是直接提交数据给action中的程序处理的(非异步处理),submit之后当前网页就转到action的程序去了,直到action中的程序重新输出网页内容或者转向其他网页。
你在submit按钮的onclick事件中不应该使用submit而是,Ajax的异步提交,类似下面的程序:
JavaScript code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function submit_realtime() {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
//接收返回值得处理函数,
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//在这里将Text area清空
documet.commentform.comment_message.value='';
}
}
xmlhttp.open("POST", "你的action处理程序", true); // true表示异步处理
xmlhttp.send();
}

xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-05-05
表单大师有这个功能,何不参考下追问

现在文本框可以不清空了,下拉框还是不行