欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實現(xiàn)三級級聯(lián)下拉框

 更新時間:2016年04月17日 14:35:31   投稿:lijiao  
這篇文章主要介紹了php實現(xiàn)三級級聯(lián)下拉框,上網(wǎng)翻找了許多三級級聯(lián)下拉框?qū)崿F(xiàn)的資料,下面分享給大家

這是我在網(wǎng)上查找到的php實現(xiàn)三級級聯(lián)下拉框的資料,共享個大家,大家一起進步,具體內(nèi)容如下

index.php:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Ajax聯(lián)動菜單</title>
<script language="javascript" type="text/javascript" src="aa.js"></script>
</head>
<body>
<form>
<label>
<select name="sel" id="sel" onChange="showMenu(this.value);">
 <option>一級分類</option>
<?php
$conn = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());
mysql_select_db('fitment', $conn) or die ('Can\'t use database : ' . mysql_error());
mysql_query("set names 'gb2312'");
$str = "SELECT * FROM `fitment_sort` where supid = '0' ORDER BY `id` ASC";
$result = mysql_query($str) or die("Invalid query: " . mysql_error());
if($result)   while ($arr = mysql_fetch_array($result)){
    echo <<<EOD
<option value={$arr["id"]}>{$arr["name"]}</option>
EOD; }
mysql_close($conn);
?>
</select>
</label>
<label>
<select name="sel2" id="sel2" onChange="showMenu2(this.value)">
 <option>二級分類</option>
 </select>
</label>
<label>
<select name="sel3" id="sel3">
 <option>三級分類</option>
</select>
</label>
</form>
<input type=button value="send value" onClick="alert(document.getElementByIdx_x_xx_x_xx('sel').options[document.getElementByIdx_x_xx_x_xx('sel').selectedIndex].text + '-' + document.getElementByIdx_x_xx_x_xx('sel2').options[document.getElementByIdx_x_xx_x_xx('sel2').selectedIndex].text + '-' + document.getElementByIdx_x_xx_x_xx('sel3').options[document.getElementByIdx_x_xx_x_xx('sel3').selectedIndex].text)">
</body>
</html>

aa.js

<!--
var xmlHttp
var xmlHttp2
//函數(shù)showMenu(str) - 功能函數(shù)1
function showMenu(str) xmlHttp=GetXmlHttpObject()    //調(diào)用GetXmlHttpObject()函數(shù),創(chuàng)建XMLHttpRequest對象
if (xmlHttp==null)        //如果創(chuàng)建失敗,則 alert ("Browser does not support HTTP Request")
 return 
var url="get2.php"        //定義url , 其主要讀取數(shù)據(jù)庫
url=url+"?q="+str
url=url+"&sid="+Math.random()  //Math對象的random方法,取隨機數(shù)
xmlHttp.onreadystatechange=stateChanged //設(shè)置當(dāng)XMLHttpRequest對象xmlHttp狀態(tài)改變時調(diào)用的函數(shù),注意函數(shù)名后不要添加小括號
xmlHttp.open("GET",url,true)  //使用XMLHttpRequest對象的open()方法 , 創(chuàng)建HTTP請求
xmlHttp.send(null)        //使用XMLHttpRequest對象的open()方法 , 發(fā)送HTTP請求
}
//函數(shù)showMenu(str) - 功能函數(shù)1
function showMenu2(str)
{
xmlHttp2=GetXmlHttpObject()    //調(diào)用GetXmlHttpObject()函數(shù),創(chuàng)建XMLHttpRequest對象
if (xmlHttp2==null)        //如果創(chuàng)建失敗,則 alert ("Browser does not support HTTP Request")
 return 
var url="get2.php"        //定義url , 其主要讀取數(shù)據(jù)庫
url=url+"?q2="+str
url=url+"&sid="+Math.random()  //Math對象的random方法,取隨機數(shù)
xmlHttp2.onreadystatechange=stateChanged2 //設(shè)置當(dāng)XMLHttpRequest對象xmlHttp狀態(tài)改變時調(diào)用的函數(shù),注意函數(shù)名后不要添加小括號
xmlHttp2.open("GET",url,true)  //使用XMLHttpRequest對象的open()方法 , 創(chuàng)建HTTP請求
xmlHttp2.send(null)        //使用XMLHttpRequest對象的open()方法 , 發(fā)送HTTP請求
}
//函數(shù)BuildSel() , 根據(jù)返回的的字串 , 重新構(gòu)建新的下拉菜單控件Select - 功能函數(shù)2
function BuildSel(str,sel)   //先清空原來的數(shù)據(jù).
  sel.options.length=0;   var arrstr = new Array();   arrstr = str.split(",");
  if(str.length>0)      //循環(huán)
    for(var i=0;i<arrstr.length;i++)       var subarrstr=new Array();       subarrstr=arrstr[i].split("|");
      sel.options.add(new Option(subarrstr[1],subarrstr[0]));     sel.options[0].selected=true; }
//函數(shù)stateChanged() - 響應(yīng)HTTP請求狀態(tài)變化
function stateChanged() //判斷XMLHttpRequest對象的readyState屬性值是否為4,如果為4表示異步調(diào)用完成(注意:異步調(diào)用完成 不代表 異步調(diào)用成功)
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") //如果異步調(diào)用成功 --> XMLHttpRequest對象的status屬性值為200 , html文件在本地運行,則xmlHttp.status的返回值為0,故應(yīng)該加上xmlHttp.status==0
 if(xmlHttp.status==200 || xmlHttp.status==0)     //調(diào)用文檔對象模型DOM的getElementById()方法查找html文件中的標簽txtHint ,
     //innerHTML為IE瀏覽器中的屬性,可以用來更改標簽間文本的內(nèi)容 ,
     //xmlHttp.responseText , 通過XMLHttpRequest的responseText屬性來獲取數(shù)據(jù) responseText,結(jié)果為字符串;responseXML,結(jié)果為XML形式
//     document.getElementByIdx_x_xx_x_xx("txtHint").innerHTML=xmlHttp.responseText
     BuildSel(xmlHttp.responseText,document.getElementsByTagName_r("*").sel2)
     showMenu2(document.getElementsByTagName_r("*").sel2.value); }
}
//函數(shù)stateChanged() - 響應(yīng)HTTP請求狀態(tài)變化
function stateChanged2() //判斷XMLHttpRequest對象的readyState屬性值是否為4,如果為4表示異步調(diào)用完成(注意:異步調(diào)用完成 不代表 異步調(diào)用成功)
if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") //如果異步調(diào)用成功 --> XMLHttpRequest對象的status屬性值為200 , html文件在本地運行,則xmlHttp.status的返回值為0,故應(yīng)該加上xmlHttp.status==0
 if(xmlHttp2.status==200 || xmlHttp2.status==0)     //調(diào)用文檔對象模型DOM的getElementById()方法查找html文件中的標簽txtHint ,
     //innerHTML為IE瀏覽器中的屬性,可以用來更改標簽間文本的內(nèi)容 ,
     //xmlHttp.responseText , 通過XMLHttpRequest的responseText屬性來獲取數(shù)據(jù) responseText,結(jié)果為字符串;responseXML,結(jié)果為XML形式
//     document.getElementByIdx_x_xx_x_xx("txtHint").innerHTML=xmlHttp.responseText
     BuildSel(xmlHttp2.responseText,document.getElementsByTagName_r("*").sel3) }
}
//函數(shù)GetXmlHttpObject() - 創(chuàng)建XMLHttpRequest對象,即創(chuàng)建一個異步調(diào)用對象
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; -->

get2.php

<?php header('Content-Type:text/html;charset=GB2312'); $conn = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());
mysql_select_db('fitment', $conn) or die ('Can\'t use database : ' . mysql_error());
mysql_query("set names 'gb2312'");
//如果傳遞過來q
if($_GET["q"]){
$strs = "SELECT * FROM fitment_sort WHERE supid=' ".$_GET["q"]."' ";
//echo $str;
$results = mysql_query($strs) or die("Invalid query: " . mysql_error());
if($results)   while ($arrs = mysql_fetch_array($results)){
    $strings .= $arrs["id"]."|".$arrs["name"].",";   }
  echo substr($strings,0,strlen($strings)-1); }
//如果傳遞過來q2
if($_GET["q2"]){
$str = "SELECT * FROM fitment_sort WHERE supid= '".$_GET["q2"]."'";
//echo $str;
$result = mysql_query($str) or die("Invalid query: " . mysql_error());
if($result)   while ($arr = mysql_fetch_array($result)){
    $string .= $arr["id"]."|".$arr["name"].",";   }   echo substr($string,0,strlen($string)-1); }
mysql_close($conn);
?>

以上就是php實現(xiàn)三級級聯(lián)下拉框的相關(guān)代碼,希望對大家學(xué)習(xí)php程序設(shè)計有所幫助。

相關(guān)文章

  • PHP開發(fā)需要注意的安全問題

    PHP開發(fā)需要注意的安全問題

    php開發(fā)過程中,需要注意的安全細節(jié),其實不只是php其它語言通用。
    2010-09-09
  • Swoole 1.10.0新版本發(fā)布,增加了多項新特性

    Swoole 1.10.0新版本發(fā)布,增加了多項新特性

    最近Swoole 1.10.0版本發(fā)布了,增加多項新特性,所以下面這篇文章主要給大家介紹了關(guān)于Swoole 1.10.0版本中新特性的相關(guān)資料,分享出來供大家參考學(xué)習(xí),需要的朋友可以參考下
    2018-01-01
  • 提高PHP編程效率的方法

    提高PHP編程效率的方法

    PHP開發(fā)中需要注意的問題,這樣要吧提高PHP編程效率
    2013-11-11
  • PHP自動選擇 連接本地還是遠程數(shù)據(jù)庫

    PHP自動選擇 連接本地還是遠程數(shù)據(jù)庫

    假設(shè)我們要在test.php文件中操作虛擬主機的數(shù)據(jù)庫,則首先要在本地調(diào)試,那么必然要連接本地、遠程兩個不同的數(shù)據(jù)庫,問題:怎么讓test.php自動識別當(dāng)下該連接本地還是遠程數(shù)據(jù)庫呢?
    2010-12-12
  • php面試實現(xiàn)反射注入的詳細方法

    php面試實現(xiàn)反射注入的詳細方法

    在本篇文章里小編給大家整理了關(guān)于php面試怎么實現(xiàn)反射注入的相關(guān)知識點,需要的朋友們學(xué)習(xí)下。
    2019-09-09
  • 一些PHP Coding Tips(php小技巧)[2011/04/02最后更新]

    一些PHP Coding Tips(php小技巧)[2011/04/02最后更新]

    以下是一些PHP Coding Tips. 當(dāng)然, 這些Tips并不一定僅僅局限于PHP.大家有什么好的心得, 歡迎直接回復(fù)本文與更多的人分享.. 謝謝
    2011-05-05
  • PHP工廠模式Factory Pattern的實現(xiàn)及特點

    PHP工廠模式Factory Pattern的實現(xiàn)及特點

    工廠模式,是一種實例化對象的方式,只要輸入需要實例化對象的名字,就可以通過工廠對象的相應(yīng)工廠函數(shù)來制造你需要的對象,工廠模式的最主要作用就是對象創(chuàng)建的封裝、簡化創(chuàng)建對象操作
    2023-03-03
  • 解決163/sohu/sina不能夠收到PHP MAIL函數(shù)發(fā)出郵件的問題

    解決163/sohu/sina不能夠收到PHP MAIL函數(shù)發(fā)出郵件的問題

    最近準備改改自己的個人主頁,加上發(fā)郵件到功能,發(fā)現(xiàn)居然不是那么好用。gmail和msn可以收到郵件,但是163/sina/sohu的郵箱居然都收不到,非常郁悶。其實代碼也很簡單。 php manual 已經(jīng)說得相當(dāng)清楚了。
    2009-03-03
  • Pear DB 新手入門指南教程

    Pear DB 新手入門指南教程

    通過 Pear DB可以從查詢結(jié)果獲得更多有用的數(shù)據(jù)信息 。這些方法有: numRows(): 通過一個"SELECT" 查詢返回所有數(shù)據(jù)的數(shù)量。
    2008-11-11
  • 非常實用的php驗證碼類

    非常實用的php驗證碼類

    這篇文章主要為大家分享了非常實用的php驗證碼類,感興趣的小伙伴們可以參考一下
    2016-05-05

最新評論