当前位置: 首页 > 工具软件 > jSelect > 使用案例 >

layui select 选择事件

邢运良
2023-12-01
<div class="layui-input-inline">
    <select name="province" lay-filter="province" id="prov_id">
        <option value="">请选择省份</option>
        {volist name="province" id = "vo"}
        <option value="{$vo['code']}" >{$vo['name']}</option>
        {/volist}
    </select>
</div>
<div class="layui-input-inline">
    <select name="city_id" id='city_id' lay-filter="city">
    </select>
</div>
<div class="layui-input-inline">
    <select name='area_id' id='area_id' lay-filter="areas">
    </select>
</div>

如果想获取select 的值 如

form.on("select.province",function(data){

console.log(data.value);/输出的为selected的值

如果是三级联动,使其展现出城市,那么则是使用

form.on('select(province)',function(data){  //获取省id,取出对应的市信息
    var html="<option value=''>请选择</option>";
    var prov_id = data.value;
    // console.log(prov_id);
    if(prov_id ==110000 || prov_id ==120100 || prov_id ==310100 || prov_id ==500000){
        $("#city_id").html("<option value=''>请选择地区</option>");
        $.post(base_url+"admin/admin/getCity",{prov_id:prov_id},function(data){
            $(data).each(function(k,v){
                $(v).each(function(kk,vv){
                    html +="<option value='"+ vv.code +"'> "+vv.name +" </option>";
                });
            });
            $('#area_id').html(html);
            form.render('select');
        },"json");
        $('#area_id').html("<option value=''>请选择地区</option>");
    }else{
        $("#city_id").parent().show();
        $.post(base_url+"admin/Admin/getCity",{prov_id:prov_id},function(data){
            // console.log(data);
            $(data).each(function(k,v){
                $(v).each(function(kk,vv){
                    html +="<option value='"+ vv.code +"'> "+vv.name +" </option>";
                });
            });
            $('#city_id').append(html);
            form.render('select');
        },"json");
        $('#area_id').html("<option value=''>请选择地区</option>");
    }

});

})

 类似资料: