当前位置:编程学习 > php >>

PHP 二级联动问题

二级联动的时候 选择二级分类 里面同时还显示一级分类,如何修正 代码如下 JS: var http_request=false; function send_request(url){//初始化,指定处理函数,发送请求的函数 http_request=false; //开始初始化XMLHttpRequest对象 if(window.XMLHttpRequest){//Mozilla浏览器 http_request=new XMLHttpRequest(); if(http_request.overrideMimeType){//设置MIME类别 http_request.overrideMimeType("text/xml"); } } else if(window.ActiveXObject){//IE浏览器 try{ http_request=new ActiveXObject("Msxml2.XMLHttp"); }catch(e){ try{ http_request=new ActiveXobject("Microsoft.XMLHttp"); }catch(e){} } } if(!http_request){//异常,创建对象实例失败 window.alert("创建XMLHttp对象失败!"); return false; } http_request.onreadystatechange=processrequest; //确定发送请求方式,URL,及是否同步执行下段代码 http_request.open("GET",url,true); http_request.send(null); } //处理返回信息的函数 function processrequest(){ if(http_request.readyState==4){//判断对象状态 if(http_request.status==200){//信息已成功返回,开始处理信息 document.getElementById(reobj).style.display = ''; document.getElementById(reobj).innerHTML=http_request.responseText; if(reobj.length == 0){ document.getElementById("Brand").style.display = 'none'; } } else{//页面不正常 alert("您所请求的页面不正常!"); } } } function getclass(obj){ var Id=document.form1.Class.value; send_request('?Id='+Id); reobj=obj; } PHP代码如下: <?php include("inc/conn.php"); header("Content-type: text/html;charset=utf-8");//输出编码,避免中文乱码 $Id=$_GET['Id']; $sql="select * from brand where Class=$Id"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ echo '<option value=\"'.$rows['Id'].'\">'; echo $rows['Title']; echo "</option>\n"; } ?> <script language="javascript" src="js/1.js"></script> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>ajax2</title> </head> <body> <form name="form1"> <select name="Class" id="Class" style="width:100px;" onChange="getclass('Brand');"> <option selected="selected">请选择</option> <? $rs=mysql_query("select * from class order by Id desc limit 0,30"); while($ap=mysql_fetch_array($rs)) {?> <option value="<? echo $ap["Id"]?>"> <? echo $ap["Title"]?> </option> <? }?> </select> <select name="Brand"id="Brand" style="width:100px;display:none;"> </select> </form> </body> </html>
补充:希望高手指点 没问题后追分
在线等~~~~~~
答案:用户先选择第一个列别中的内容(大类),鼠标失去焦点时触发事件中根据第一个大类选中的内容用Ajax到后台提取第二个类别中需要的内容  然后用jquery的append 方法把获取到的数据加到第二个列表中就OK了

上一个:php里面的@有什么用。 如dedecms /install/index.php 里面的@set_time_limit(0);
下一个:php在哪里学较好

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,