实用的mysql ajax php 三级级联下拉框.doc
《实用的mysql ajax php 三级级联下拉框.doc》由会员分享,可在线阅读,更多相关《实用的mysql ajax php 三级级联下拉框.doc(4页珍藏版)》请在三一办公上搜索。
1、实用的mysql ajax php 三级级联下拉框1,昨天弄了一个简单的三级级联下拉框。超级实用。index.php:html head meta http-equiv=Content-Typecontent=text/html;charset=gb2312title Ajax联动菜单/title script language=javascripttype=text/javascriptsrc=aa.js/script/head body form label select name=selid=selonChange=showMenu(this.value);option一级分类/opti
2、on?php$conn=mysql_connect(localhost,root,)or die(Could not connect:.mysql_error();mysql_select_db(fitment,$conn)or die(Cant use database:.mysql_error();mysql_query(set namesgb2312);$str=SELECT*FROMfitment_sortwhere supid=0ORDER BYidASC;$result=mysql_query($str)or die(Invalid query:.mysql_error();if(
3、$result)while($arr=mysql_fetch_array($result)echo EOD option value=$arrid$arrname/option EOD;mysql_close($conn);?/select/label label select name=sel2id=sel2onChange=showMenu2(this.value)option二级分类/option/select/label label select name=sel3id=sel3option三级分类/option/select/label/form input type=button
4、value=send valueonClick=alert(document.getElementById(sel).optionsdocument.getElementById(sel).selectedIndex.text+-+document.getElementById(sel2).optionsdocument.getElementById(sel2).selectedIndex.text+-+document.getElementById(sel3).optionsdocument.getElementById(sel3).selectedIndex.text)/body/html
5、 aa.js!-var xmlHttp var xmlHttp2/函数showMenu(str)-功能函数1 function showMenu(str)xmlHttp=GetXmlHttpObject()/调用GetXmlHttpObject()函数,创建XMLHttpRequest对象if(xmlHttp=null)/如果创建失败,则alert(Browser does not support HTTP Request)returnvar url=get2.php/定义url,其主要读取数据库url=url+?q=+str url=url+&sid=+Math.random()/Math对
6、象的random方法,取随机数xmlHttp.onreadystatechange=stateChanged/设置当XMLHttpRequest对象xmlHttp状态改变时调用的函数,注意函数名后不要添加小括号xmlHttp.open(GET,url,true)/使用XMLHttpRequest对象的open()方法,创建HTTP请求xmlHttp.send(null)/使用XMLHttpRequest对象的open()方法,发送HTTP请求/函数showMenu(str)-功能函数1 function showMenu2(str)xmlHttp2=GetXmlHttpObject()/调用G
7、etXmlHttpObject()函数,创建XMLHttpRequest对象if(xmlHttp2=null)/如果创建失败,则alert(Browser does not support HTTP Request)returnvar url=get2.php/定义url,其主要读取数据库url=url+?q2=+str url=url+&sid=+Math.random()/Math对象的random方法,取随机数xmlHttp2.onreadystatechange=stateChanged2/设置当XMLHttpRequest对象xmlHttp状态改变时调用的函数,注意函数名后不要添加小
8、括号xmlHttp2.open(GET,url,true)/使用XMLHttpRequest对象的open()方法,创建HTTP请求xmlHttp2.send(null)/使用XMLHttpRequest对象的open()方法,发送HTTP请求/函数BuildSel(),根据返回的的字串,重新构建新的下拉菜单控件Select-功能函数2 function BuildSel(str,sel)/先清空原来的数据.sel.options.length=0;/定义一个数组对象var arrstr=new Array();/以,号拆分传入的字串,并存入数组arrstr=str.split(,);if(s
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实用的mysql ajax php 三级级联下拉框 实用 mysql 三级 级联 下拉

链接地址:https://www.31ppt.com/p-2388773.html