这样子的情况下,只要在文本框输入内容,就会自动提交到ajax,怎么才能点击提交按钮才提交呢。_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 12:23:12
原创
1889人浏览过







这样子的情况下,只要在文本框输入内容,就会自动提交到ajax,怎么才能点击提交按钮才提交呢。

回复讨论(解决方案)

<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>
登录后复制


test.html?cu=&Submit=%CC%E1%BD%BB
你这样子提交后,浏览器居然在后面带出了参数,我是想用ajax的方式提交,不刷新页面显示数据?

<!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>
                    <div class="aritcle_card">
                        <a class="aritcle_card_img" href="/ai/2137">
                            <img src="https://img.php.cn/upload/ai_manual/000/000/000/175680088531646.png" alt="提客AI提词器">
                        </a>
                        <div class="aritcle_card_info">
                            <a href="/ai/2137">提客AI提词器</a>
                            <p>「直播、录课」智能AI提词,搭配抖音直播伴侣、腾讯会议、钉钉、飞书、录课等软件等任意软件。</p>
                            <div class="">
                                <img src="/static/images/card_xiazai.png" alt="提客AI提词器">
                                <span>64</span>
                            </div>
                        </div>
                        <a href="/ai/2137" class="aritcle_card_btn">
                            <span>查看详情</span>
                            <img src="/static/images/cardxiayige-3.png" alt="提客AI提词器">
                        </a>
                    </div>
                
登录后复制

<!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>
登录后复制

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号