select中的简单联动

根据医院标号选医生

jquery:

<script type="text/javascript">
$(function(){
$('#hospital_id').change(function(){
var hosid=$(this).val();
$.getJSON('__URL__/getExpert',{id:hosid},function(data){

$("#expert_id option[value!='0']").remove();
for(var i=0;i<data.length;i++)
{
var s="<option value="+data[i].exp_id+">"+data[i].exp_name+"</option>";
$(s).appendTo("#expert_id");
}
});

});
});
</script>

 

HTML:

<li>
<label>专家</label>
<select name="expert_id" id="expert_id">
<option value="0">无</option>
<option value="{$experts.exp_id}" selected=selected>&nbsp;&nbsp;{$experts.exp_name}</option>
</foreach>
</select>
</li>

<li>
<label>项目</label>
<select name="project_id">

<option value="0">无</option>
<option value="1">医院1</option>

<option value="2">医院2</option>

<option value="3">医院3</option>
</foreach>
</select>
</li>

 

function:

function getExpert()
{
$M=M('expert');
$hos_id=$_GET['id'];
$data=$M->where(array('hos_id'=>$hos_id))->select();
$this->ajaxReturn($data);
}

posted @ 2014-11-27 20:40  S-Ping  阅读(185)  评论(0编辑  收藏  举报