您的位置:首页 > Web前端 > JQuery

jquery 无限极联动【地区】

2017-01-08 20:10 246 查看
<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: