jquery二级联动下拉框

html代码片段

<div class="form-group">
		<div class=" col-xs-12 col-sm-3 col-md-3 col-lg-3" >
		    <label class="col-xs-12 col-sm-5 col-md-5 control-label input_lable order_style_labe" style="width: 35%;">线路</label>
		    <select name= "line_code" id="line_code" class="form-control input_content order_style_content" style="width: 65%;">
		        <option value="">全部</option>
		        <option value="1">徐凤年</option>
		        <option value="2">陈平安</option>
		        {/loop}
		    </select>
		</div>
		<div class=" col-xs-12 col-sm-3 col-md-3 col-lg-3" >
		   <label class="col-xs-12 col-sm-5 col-md-5 control-label input_lable order_style_labe" style="width: 35%;">班次</label>
		    <select name= "sch_code" id="sch_code" class="form-control input_content order_style_content" style="width: 65%;">
		        <option value="">全部</option>
		         <option value="1">洛阳</option>
		        <option value="2">阮秀</option>
		    </select>
		</div>
</div>

jQuery代码片段

<script>
    $("#line_code").change(function () {
        var $this = $(this);
        var line_code = $this.find("option:selected").val();
        console.log(line_code);
        $.ajax({
            type: "post",
            url: "http://hello.com.cn/example.php",
            data: { line_code:  line_code},
            dataType: "json",
            success: function (ret) {
                console.log(ret.success);
                var tmp = '<option value="">全部</option>';
                if (ret.success) {
                    var data = ret.data;
                    console.log(data);
                    var length = data.length;
                    for(var i=0;i<length;i++){
                        tmp += '<option value="'+data[i].sch_code+'" >'+data[i].sch_code+'</option>';
                    }
                    console.log(tmp)
                    $('#sch_code').empty();
                    $('#sch_code').append(tmp);
                }
            }
        });
    });
</script>

PHP后台代码片段

<?php
$line_code = $_GPC['line_code'];
if(!empty($line_code)) {
    $sch_codes = pdo_getall('zc2_ticket_order',['line_code'=>$line_code],'sch_code');
}
echo json_encode(['success'=>'true','msg'=>'请求成功','data'=>$sch_codes]);exit();
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值