开发者社区> 问答> 正文

js或者jq实现二级联动,select实现,要求进入页面默认初始化状态。

这是数据格式,求助。parent_id为零的为父级。

[
 {
 "id": 1,
 "title": "餐饮美食",
 "parent_id": 0,
 "sort": 1
 },
 {
 "id": 2,
 "title": "丽人美发",
 "parent_id": 0,
 "sort": 1
 },
 {
 "id": 3,
 "title": "KTV酒店",
 "parent_id": 0,
 "sort": 1
 },
 {
 "id": 4,
 "title": "啊三大的",
 "parent_id": 0,
 "sort": 1
 },
 {
 "id": 5,
 "title": "休闲娱乐",
 "parent_id": 0,
 "sort": 1
 },
 {
 "id": 6,
 "title": "自助火锅",
 "parent_id": 0,
 "sort": 1
 },
 {
 "id": 7,
 "title": "玩",
 "parent_id": 0,
 "sort": 1
 },
 {
 "id": 8,
 "title": "餐饮吧",
 "parent_id": 1,
 "sort": 2
 },
 {
 "id": 9,
 "title": "剪发吧·",
 "parent_id": 2,
 "sort": 2
 },
 {
 "id": 10,
 "title": "ktv哦",
 "parent_id": 3,
 "sort": 2
 },
 {
 "id": 11,
 "title": "啊飒飒色彩哦",
 "parent_id": 4,
 "sort": 2
 },
 {
 "id": 12,
 "title": "休闲养生",
 "parent_id": 5,
 "sort": 2
 },
 {
 "id": 13,
 "title": "火锅·海底捞",
 "parent_id": 6,
 "sort": 2
 },
 {
 "id": 14,
 "title": "电影",
 "parent_id": 7,
 "sort": 2
 },
 {
 "id": 15,
 "title": "美食1",
 "parent_id": 1,
 "sort": 0
 },
 {
 "id": 16,
 "title": "美发2",
 "parent_id": 1,
 "sort": 0
 },
 {
 "id": 17,
 "title": "美发3",
 "parent_id": 1,
 "sort": 0
 },
 {
 "id": 18,
 "title": "美发4",
 "parent_id": 1,
 "sort": 0
 },
 {
 "id": 19,
 "title": "美发5",
 "parent_id": 2,
 "sort": 0
 },
 {
 "id": 20,
 "title": "美发6",
 "parent_id": 2,
 "sort": 0
 },
 {
 "id": 21,
 "title": "美发7",
 "parent_id": 2,
 "sort": 0
 },
 {
 "id": 23,
 "title": "333",
 "parent_id": 1,
 "sort": 0
 },
 {
 "id": 24,
 "title": "xlh2",
 "parent_id": 1,
 "sort": 0
 }
 ]

展开
收起
杨冬芳 2016-06-16 16:41:10 2151 0
1 条回答
写回答
取消 提交回答
  • IT从业

    http://jsfiddle.net/7yvxantu/1/点击预览
    想要这样的效果?给第一个select绑定change事件,然后更改第二个select的html就可以了。

    2019-07-17 19:41:19
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
JavaScript函数 立即下载
Delivering Javascript to World 立即下载
编程语言如何演化-以JS的private为例 立即下载