当我点击"提交第二个"时,页面将转到first.html.我希望它转到second.html
的index.html
<body onload="secondForm();">
<script type="text/javascript">
function ajaxRequest(){
var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] // activeX versions in IE
if (window.ActiveXObject){ // test support for ActiveXObject in IE
for (var i=0; i<activexmodes.length; i++){
try{
return new ActiveXObject(activexmodes[i])
}
catch(e){
// suppress
}
}
}
else if (window.XMLHttpRequest) // mozilla,safari,chrome,opera
return new XMLHttpRequest()
else
return false
}
function secondForm(id) {
var mygetrequest=new ajaxRequest()
mygetrequest.onreadystatechange=function() {
if (mygetrequest.readyState==4) {
if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1) {
document.getElementById("secondForm").innerHTML=mygetrequest.responseText
}
}
}
mygetrequest.open("POST", "secondForm.html, true)
mygetrequest.send(null)
}
</script>
<form method="POST" action="first.html" id="firstForm">
<span id="secondForm"></span>
<input type="submit" value="Submit First">
</form>
Run Code Online (Sandbox Code Playgroud)
secondForm.html
<form method="POST" action="second.html" id="secondForm">
<input type="submit" value="Submit Second">
</form>
Run Code Online (Sandbox Code Playgroud)