select2 实现多级联动下拉框,分页,搜索

这篇博客介绍了如何利用select2库创建具有多级联动、分页和搜索功能的下拉框。文章详细阐述了在不同级别下拉框之间传递值、动态加载数据以及调用ajaxSelect2函数实现分页搜索的方法。
摘要由CSDN通过智能技术生成

需要引入

select2.full.min.js   zh-CN.js  select2.css

    var select0 = $(".select0").children("select");
    var select1 = $(".select1").children("select");
    var select2 = $(".select2").children("select");
    var select3 = $(".select3").children("select");
    var select4 = $(".select4").children("select");


//给第一个下拉框的SelectChanged事件
    select0.change(function (){

//取得当前下拉框的值
        var select0Value = $(".select0").children("select").val();
//当第一个下拉框内容改变的时候,第三个下拉框要隐藏起来
        select1.parent().hide();
        select2.parent().hide();
        select3.parent().hide();
        select4.parent().hide();

        if(select0Value !="")
        {
            var options = {
                url: ctx + "xxx/xxx",      // 数据接口url
                pageSize: 20, // 每次加载的数据条数
                value: "userId",  // 下拉框value字段名称
                name: "userName", // 下拉框显示字段名称
                selected: [], // 默认选中项,格式:[{id:1,text:"选项1"},{id:2,text:"选项2"}]
                param0: select0Value
            };
            ajaxSelect2("myselect1",options);
        }
    });


    select1.change(function (){
        var select0Value = $(".select0").children("select").val();
        var select1Value = $(".select1").children("select").val();
        select2.parent().hide();
        select3.parent().hide();
        select4.parent().hide();
        if(select1Value !="" && select1Value!=null)
        {
            var options = {
                url: ctx + "xxx

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值