Maison >interface Web >tutoriel HTML >这样子的情况下,只要在文本框输入内容,就会自动提交到ajax,怎么才能点击提交按钮才提交呢。_html/css_WEB-ITnose
<form ><input type="text" name="cu" id="cu" /><input type="submit" name="Submit" value="提交" onSubmit="showCustomer(document.getElementById('cu').value)" /></form>
<form ><input type="text" name="cu" id="cu" /><input type="submit" name="Submit" value="提交" onSubmit="showCustomer(document.getElementById('cu').value)" /></form>
<form ><input type="text" name="cu" id="cu" /><input type="submit" name="Submit" value="提交" onSubmit="showCustomer(document.getElementById('cu').value)" /></form>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><form name="form1"><input type="text" name="cu" id="cu" /><input type="submit" name="Submit" value="提交" onclick="return showCustomer(document.getElementById('cu').value)" /> </form><script type="text/javascript">function showCustomer(e){ alert(e); return false;}</script></body></html>
对 不起input元素没有onsubmit事件.在alert(e),哪里写你的ajax代码
对 不起input元素没有onsubmit事件.在alert(e),哪里写你的ajax代码
你太客气了,我试试看,感谢了。
对 不起input元素没有onsubmit事件.在alert(e),哪里写你的ajax代码
你太客气了,我试试看,感谢了。
把js文件换成我的。。还是会test.html?cu=&Submit=%CC%E1%BD%BB
贴一下你写的吧
<form><input type="text" name="customers" id="customers" /><input type="submit" name="Submit" value="提交" onClick="return showCustomer(document.getElementById('customers').value)" /> </form><script type="text/javascript">var xmlHttpfunction showCustomer(str){ xmlHttp=GetXmlHttpObject();if (xmlHttp==null) { alert ("您的浏览器不支持AJAX!"); return; } var url="getcustomer.php";url=url+"?q="+str;url=url+"&sid="+Math.random();xmlHttp.onreadystatechange=stateChanged;xmlHttp.open("GET",url,true);xmlHttp.send(null);}function stateChanged(){ if (xmlHttp.readyState==4){ document.getElementById("txtHint").innerHTML=xmlHttp.responseText;}}function GetXmlHttpObject(){var xmlHttp=null;try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }return xmlHttp;</script><p><div id="txtHint"><b>客户信息将在此处列出。</b></div></p>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><form><input type="text" name="customers" id="customers" /><input type="submit" name="Submit" value="提交" onClick="return showCustomer(document.getElementById('customers').value)" /> </form><script type="text/javascript">var xmlHttpfunction showCustomer(str){ xmlHttp=GetXmlHttpObject(); if (xmlHttp==null){ alert ("您的浏览器不支持AJAX!"); return false; } var url="getcustomer.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); return false;}function stateChanged(){ if (xmlHttp.readyState==4){ document.getElementById("txtHint").innerHTML=xmlHttp.responseText; }}function GetXmlHttpObject(){ var xmlHttp=null; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e) { // Internet Explorer try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp;}</script><p><div id="txtHint"><b>客户信息将在此处列出。</b></div></p></body></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><form><input type="text" name="customers" id="customers" /><input type="submit" name="Submit" value="提交" onClick="return showCustomer(document.getElementById('customers').value)" /> </form><script type="text/javascript">var xmlHttpfunction showCustomer(str){ xmlHttp=GetXmlHttpObject(); if (xmlHttp==null){ alert ("您的浏览器不支持AJAX!"); return false; } var url="getcustomer.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); return false;}function stateChanged(){ if (xmlHttp.readyState==4){ document.getElementById("txtHint").innerHTML=xmlHttp.responseText; }}function GetXmlHttpObject(){ var xmlHttp=null; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e) { // Internet Explorer try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp;}</script><p><div id="txtHint"><b>客户信息将在此处列出。</b></div></p></body></html>
大师请看我的这个帖子。。
http://bbs.csdn.net/topics/390542913
<form><input type="text" name="customers" id="customers" /><input type="submit" name="Submit" value="提交" onClick="return showCustomer(document.getElementById('customers').value)" /> </form><script type="text/javascript">var xmlHttpfunction showCustomer(str){ xmlHttp=GetXmlHttpObject();if (xmlHttp==null) { alert ("您的浏览器不支持AJAX!"); return; } var url="getcustomer.php";url=url+"?q="+str;url=url+"&sid="+Math.random();xmlHttp.onreadystatechange=stateChanged;xmlHttp.open("GET",url,true);xmlHttp.send(null);}function stateChanged(){ if (xmlHttp.readyState==4){ document.getElementById("txtHint").innerHTML=xmlHttp.responseText;}}function GetXmlHttpObject(){var xmlHttp=null;try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }return xmlHttp;</script><p><div id="txtHint"><b>客户信息将在此处列出。</b></div></p>