ld—jquery多級聯動外掛程式

來源:互聯網
上載者:User

這是個不錯多級聯動外掛程式,用起來比較簡單實用,如果非要吹毛求疵的話,就是需要負載檔案少多一點.這個是外掛程式作者的部落格,裡有有執行個體和下載,大家想想要詳細瞭解可以去看看http://www.36ria.com/2955 因為原版裡是串連資料庫,想下到本地看效果很費勁.我這裡寫個簡單用法,用於給新手立馬上手能用.

test.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>$.ld——jquery多級聯動外掛程式 V1.0</title>
<link href="style/css/base.css" rel="stylesheet" type="text/css" />
<link href="style/css/demo.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header" class="clearfix">
<div id="logo" class="l"><img src="style/images/logo.png" /></div>
<div class="l">
                <h2>$.ld——jquery多級聯動外掛程式 V1.0</h2>
                <p>作者:明河共影,部落格:<a href="http://www.36ria.com/">RIA之家</a></p>
                <p>外掛程式文檔:<a href="http://www.36ria.com/2955">http://www.36ria.com/2955</a></p>        
        </div>
</div>
<h2>樣本1:最基礎的樣本示範,讀取json</h2>
<table width="700" border="0" cellspacing="0" cellpadding="0" class="tab1">
    <tr>
     <td>國家</td>
     <td><select    class="ld-select-1" name="country">
            <option value="">請選擇你的國家</option>
         </select>
        
        </td>
        <td>省份</td>
        <td><select    class="ld-select-1" name="province">
            <option value="">請選擇你的省份</option>
         </select>
        </td>
        <td>城市</td>
        <td><select class="ld-select-1" name="city">
            <option value="">請選擇你的城市</option>
         </select>
        </td>
        <td>區縣</td>
        <td><select class="ld-select-1" name="county">
            <option value="">請選擇你的區縣</option>
         </select>
        </td>
    </tr>
</table>
<code>
$(".ld-select-1").ld({ajaxOptions : {"url" : "get_region.php"},<br />
style : {"width" : 120}<br />
});
</code>

    

<script src="js/jquery-1.4.2.min.js"></script>
<script src="js/jquery.ld.js"></script>
<script type="text/javascript">
$(function(){
//樣本1
$(".ld-select-1").ld({ajaxOptions : {"url" : "get_region.php"},
                style : {"width" : 120}
                                            });    
})
</script>
</body>
</html>




get_region.php

<?php
ob_start();
/*
function runSQL($rsql) {
$hostname = 'localhost';// 資料庫伺服器
$username = 'root';    // 資料庫使用者名稱
$password = '123';         // 資料庫密碼
$dbname     = 'ld';     // 資料庫名
$connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
$db = mysql_select_db($dbname);
mysql_query('set names utf8');
$result = mysql_query($rsql);    
return $result;
mysql_close($connect);
}
*/
include("include/JSON.php");
/*if(isset($_GET['parent_id'])){
$where = "WHERE parent_id = ".$_GET['parent_id']." ";
}else{
$where = "WHERE parent_id = 0 ";
}*/

/*$sql = "SELECT * FROM region $where";
$result = runSQL($sql);*/

$data_type = "json";
if(isset($_GET['data_type'])){
$data_type = $_GET['data_type'];
}
if($_GET['parent_id'] == 0){
$rows = array(array('region_id'=>1,'region_name'=>"我X1"),array('region_id'=>2,'region_name'=>"我X2"),array('region_id'=>3,'region_name'=>"我X3"),array('region_id'=>4,'region_name'=>"我X4"));
}else{
$rows = array(array('region_id'=>1,'region_name'=>"我T1"),array('region_id'=>2,'region_name'=>"我T2"),array('region_id'=>3,'region_name'=>"我T3"),array('region_id'=>4,'region_name'=>"我T4"));    
}

if($data_type == "json"){
$json_str = "[";
$json = array();
foreach($rows as $row) {
/*    $r = array('region_id' => $row['region_id'],
                         'region_name' => $row['region_name']);*/
    $json[] = JSON($row);
}
$json_str .= implode(',',$json);
$json_str .= "]";
echo $json_str;    
}else if($data_type == "xml"){
        header("Content-type: text/xml;");
$xml = "<?xml version='1.0' encoding='UTF-8'?>";
$xml .= "<root>";
while ($row = mysql_fetch_array($result)) {
    $xml .= "<record>";
     $xml .= "<region_id>".$row['region_id']."</region_id>";
     $xml .= "<region_name>".$row['region_name']."</region_name>";
    $xml .= "</record>";
}
$xml .="</root>";
echo $xml;    
}
?>

這裡簡單說明下  我為了下載後就能看到效果 就把原版的資料庫連接全部注釋了  而用數組來充當資料庫返回結果  如果你是串連資料庫的話那就把注釋去掉改寫下 或者去下原版吧還有這裡我貼的是我改的兩個檔案 但並不是有這兩個就能用 我把例子上傳到這裡 想要就去下吧jquery多級聯動外掛程式及執行個體 


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.