首页 > 代码库 > select中的简单联动

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="http://www.mamicode.com/+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="http://www.mamicode.com/0">无</option>
<option value="http://www.mamicode.com/{$experts.exp_id}" selected=selected>&nbsp;&nbsp;{$experts.exp_name}</option>
</foreach>
</select>
</li>

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

<option value="http://www.mamicode.com/0">无</option>
<option value="http://www.mamicode.com/1">医院1</option>

<option value="http://www.mamicode.com/2">医院2</option>

<option value="http://www.mamicode.com/3">医院3</option>
</foreach>
</select>
</li>

 

function:

function getExpert()
{
$M=M(‘expert‘);
$hos_id=$_GET[‘id‘];
$data=http://www.mamicode.com/$M->where(array(‘hos_id‘=>$hos_id))->select();
$this->ajaxReturn($data);
}

select中的简单联动