我如何让它发挥作用
onsubmit
,而不是
onclick with a button?
我有一个表格:
<form id="form">
<label>Email:</label>
<input type="email" name="email" id="email" class="iput" placeholder="jane@doe.com" reguired="required"/>
<input type="button" id="nbut" onclick="loadXMLDoc()" value="NEXT">
</form>
该按钮可以正常调用和处理 javascript:
function loadXMLDoc() {
var xmlhttp;
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)
{
document.getElementById('response').innerHTML=xmlhttp.responseText;
document.getElementById('step1').style.display = "none";
document.getElementById('step2').style.display = "block";
}
}
var em = document.getElementById('email');
var em1 = em.value;
xmlhttp.open("GET","bin/process.php?email="+em1,true);
xmlhttp.send();
}
这只适用于按钮 onclick,我无法让它在 onsubmit 上工作,也不知道为什么..
最佳答案
onsubmit
是 <form>
元素事件。
您可以非常简单地删除 onclick
按钮中的属性并将表单更改为
<form id="form" onsubmit="loadXMLDoc(); return false;">
return false
阻止执行默认事件处理程序(表单提交)。
关于php - 处理 PHP 而不离开页面 FUNCTION onsubmit ="loadXMLdoc()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8057374/