Home >Web Front-end >JS Tutorial >Use js jquery to achieve infinite linkage_jquery

Use js jquery to achieve infinite linkage_jquery

WBOY
WBOYOriginal
2016-05-16 17:33:211128browse

今天工作需要写树形的联动,于是写了个可扩展的无限极联动下拉选项
代码写的比较凌乱 先mark有空再整理



随便截个图!
先贴数据库

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 used for page code

Copy code The code is as follows:


"; Classification";
var datas = eval(result);
$.each(datas, function(i,val){                   value='" val. id "' >" val.category_name "";
                                                              Empty outdated options
              $("select")                                                                                                                                     }
})

                     $("#select"                                                                                                                                            ; 🎜>                                                                                                           ​ })   }

},
error: false
});

}


AJAX data retrieval PHP code




Copy code


The code is as follows:

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

OK 大功告成!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn