用javascrip怎样把表单中内容完全提交到另一页面 5
2个回答
展开全部
document.XXForm.submit(); 其中,XXForm为你需要提交的表单的name值,如<form name="addForm" action="" method="post"></from>
或者用ajax发送请求,就是所谓的无刷新验证:
demo:
/*验证验证码是否正确*/
function checkRand() {
var randnum = document.getElementById('randomcode').value;
if(randnum==null || randnum==""){//验证码为空
document.getElementById('randomcodeinfo').innerHTML='验证码不能为空!';
}else{//验证码不为空
createXMLHttpRequest();
var urls="<%=request.getContextPath()%>/register";
var data = "randnum=" + randnum + "&randcheck=true";
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
if (xmlHttp.responseText != null) {
if (xmlHttp.responseText == 'error') {
document.getElementById('randomcodeinfo').innerHTML = '验证码有误!';
} else {
document.getElementById('randomcodeinfo').innerHTML = '验证码正确!';
}
}
}
}
};
xmlHttp.open("post", urls, true);
xmlHttp.setRequestHeader("CONTENT-TYPE",
"application/x-www-form-urlencoded");
xmlHttp.send(data);
}
}
</script>
或者用ajax发送请求,就是所谓的无刷新验证:
demo:
/*验证验证码是否正确*/
function checkRand() {
var randnum = document.getElementById('randomcode').value;
if(randnum==null || randnum==""){//验证码为空
document.getElementById('randomcodeinfo').innerHTML='验证码不能为空!';
}else{//验证码不为空
createXMLHttpRequest();
var urls="<%=request.getContextPath()%>/register";
var data = "randnum=" + randnum + "&randcheck=true";
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
if (xmlHttp.responseText != null) {
if (xmlHttp.responseText == 'error') {
document.getElementById('randomcodeinfo').innerHTML = '验证码有误!';
} else {
document.getElementById('randomcodeinfo').innerHTML = '验证码正确!';
}
}
}
}
};
xmlHttp.open("post", urls, true);
xmlHttp.setRequestHeader("CONTENT-TYPE",
"application/x-www-form-urlencoded");
xmlHttp.send(data);
}
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询