js+jquery 無限極聯動_PHP教程

來源:互聯網
上載者:User
今天工作需要 要寫樹形的聯動,於是寫了個可擴充的無限極聯動下拉選項

代碼寫的比較淩亂 先mark 有空再整理

操蛋!

公司連QQ都不能上 隨便截個圖!

先貼資料庫

id category_name 分類名 pid 父分類id orders 排序
1 22223331 0 1
2 2222111 1 1
12 44444 11 0
5 2222 1 1
6 2222 1 1
11 333 2 0
13 555555 12 0

頁面代碼 用的SMARTY

             請選擇分類                    {$category.category_name}                
$galleryCategory 去資料的PHP代碼為

$sql = " select * from yl_gallery_category where pid = 0";$galleryCategory = $db->query($sql);$smarty->assign("galleryCategory",$galleryCategory);

  給辭職的同事的項目擦屁股 用的原生態代碼 還是比較容易理解的

然後就是關鍵的 JS代碼了 change(val) {

 str = val;      num;      id;     num = str.substr(9,10     nownum = parseInt(num)+1;     id = $("#"+str+"" r = /^[1-9]+[0-9]*]*$/;      (!        $("select").each((index+1 >  url = 'gallery.php?act=category&pid='+"POST"'json'3000 ( result != 0 html = ""+= "請選擇分類 " datas =+= ""+val.category_name+""+= ""                $("select").each((index+1 >"#select"
          //清空過時的選項                $("select").each(function(index){                    if(index+1 > num) {                        $(this).remove();                    }                })

AJAX 取資料的PHP代碼

$sql = " select * from yl_gallery_category where pid = " .$pid;$res = $db->query($sql);if (empty($res)) {$res = 0;}echo json_encode($res);

 OK 大功告成!



http://www.bkjia.com/PHPjc/440345.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/440345.htmlTechArticle今天工作需要 要寫樹形的聯動,於是寫了個可擴充的無限極聯動下拉選項 代碼寫的比較淩亂 先mark 有空再整理 操蛋! 公司連QQ都不能上...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.