需要帮助每个人为什么我的代码有问题我想做一个两个下拉列表,。一个下拉到主数据,第二个下拉到数据主数据。然后我做了 .chzn-select 但没有任何反应,这是我的代码:
/My view //jquery.min.js 和 selected.jquery.js 和 selected.css 已加载
<script type="text/javascript">
$(".chzn-select").chosen().change(function(){
alert('here');
$("#rack > option").remove();
var id_lantai = $("#id_lantai").val();
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>power/get_rack_perlantai"+id_lantai,
success: function(rack){
$.each(rack,function(id_rack,nama_rack){
var opt = $('<option />');
opt.val(id_rack);
opt.text(nama_rack);
$('#rack').append(opt);
});
}
})
});
</script>
<tr><td>FLOOR *</td><td>:</td>
<td>
<select data-placeholder="Floor" class="chzn-select" style="width:200px;" tabindex="2" id="id_lantai" class="required" name="id_lantai" >
<option value="" val_nm_prd="">-SELECT FLOOR -</option>
<?php
foreach($id_lantai as $u){
if($u['id_lantai']==$val){
$selected="selected";
}else{
$selected="";
}
?>
<option value="<?=$u['id_lantai']?>" <?=$selected?> ><?=$u['lantai']?></option>
<?php } ?>
</select>
</td>
</tr>
<tr><td>RACK *</td><td>:</td>
<td>
<select data-placeholder="Rack" class="chzn-select" style="width:200px;" tabindex="2" id="id_rack" class="required" name="id_rack" >
<option value="" val_nm_prd="">-SELECT RACK -</option>
<?php
foreach($id_rack as $u){
if($u['id_lantai']==$vall()){
$selected="selected";
}else{
$selected="";
}
?>
<option value="<?=$u['id_rack']?>" <?=$selected?> ><?=$u['nama_rack']?></option>
<?php } ?>
</select>
</td>
</tr>
//我的控制器
function get_rack_perlantai($idlantai)
{
header('Content-Type: application/x-json; charset=utf-8');
echo(json_encode($this->power_model->get_rack($idlantai)));
}
//我的模型
function get_lantai() {
$this->db->select('id_lantai, lantai');
$query = $this->db->get('xl_lantai_server');
$lantaivariabel = array();
if ($query -> result()) {
foreach ($query->result() as $lantaix) {
$lantaivariabel[$lantaix -> id_lantai] = $lantaix -> lantai;
}
return $lantaivariabel;
}
else
{
return FALSE;
}
}
//Query untuk ajak lantai & rack
function get_rack($idlantai = null)
{
$this->db->select('id_rack, nama_rack');
if($idlantai != NULL){
$this->db->where('id_lantai', $idlantai);
}
$query = $this->db->get('xl_rack');
$xl_rack = array();
if($query->result()){
foreach ($query->result() as $rack) {
$xl_rack[$rack->id_rack] = $rack->nama_rack;
}
return $xl_rack;
}
else
{
return FALSE;
}
}
对不起,我的英语不好,.:)