1.
<script><?php $this->beginBlock('js_end') ?>
$(document).on('change','.address',function(){
var area_id = $(this).val();
var _this = $(this);
_this.nextAll().remove();
if(area_id==0){
return false;
}
var url = 'index.php?r=test/area_child';
$.getJSON(url,{'area_id':area_id},function(msg){
if(msg.length>0){
var str="<selectclass='address'><option>..请选择</option>";
$(msg).each(function(k,v){
str+="<optionvalue="+v.area_id+">"+v.area_name+"</option>";
})
str+="</select>";
_this.after(str);
}
})
})
<?php $this->endBlock() ?>
</script>
<?php $this->registerJs($this->blocks['js_end'],\yii\web\View::POS_END); ?>
2.
<script src='css/jq.js'></script>
<script>
$(document).on('change','.address',function(){
var area_id = $(this).val();
var _this = $(this);
_this.nextAll().remove();
if(area_id==0){
return false;
}
var url = 'index.php?r=test/area_child';
$.getJSON(url,{'area_id':area_id},function(msg){
if(msg.length>0){
var str = '';
str+="<select class='address'><option>..请选择</option>";
$(msg).each(function(k,v){
str+="<option value="+v.area_id+">"+v.area_name+"</option>";
})
str+="</select>";
_this.after(str);
}
})
})
</script>