jquery 无限极联动【地区】

来源:互联网 发布:赛嘉电动牙刷 知乎 编辑:程序博客网 时间:2024/05/21 10:10
<select name="region[]"  class="region" >                        <option value="">--请选择--</option>            <?php foreach ($region_data as $k => $val): ?>            <option value="<?php echo $val->region_id?>"><?php echo $val->region_name?></option>            <?php endforeach ?>    </select>    <script>        $(function(){         $(document).on('change','.region',function(){            var  region_id=$(this).val();            var _this=$(this);            if (region_id<0) {                _this.nextAll().remove();                return false;            }            $.post('publish_position',{'region_id':region_id},function(msg){                console.log(msg);                if (msg.length>0) {                      str='<select name="region[]" class="region">';                      str+='<option value="-1">--请选择--</option>';                       $(msg).each(function(k,v){                        str+='<option value='+v.region_id+'>'+v.region_name+'</option>';                       })                        str+='</select>'                       _this.nextAll().remove();                       _this.after(str);                }            },"json")          })     })</script>
0 0
原创粉丝点击