我在Codeigniter中创建了一个级联下拉列表,但第二个下拉列表没有填充在IE 9和IE 8中。以下是相关控制器:
public function buildDropEquipment($class)
// This builds the dropdown field for newly added equipment
{
//set selected class id from POST
$class = $this->input->post('class',TRUE);
error_log("class variable: ".$class." 'n", 3, "/Applications/MAMP/logs/php_error.log");
//run the query for the cities we specified earlier
$this->load->model('admin/MEquipment');
$equipmentData['equipmentDrop']=$this->MEquipment->getEquipmentByClass($class);
$output = null;
foreach ($equipmentData['equipmentDrop']->result() as $row)
{
//here we build a dropdown item line for each query result
$output .= "<option value='".$row->type."'>".$row->type."</option>";
}
echo $output;
}
以下是我的观点:
<script type="text/javascript">
$(document).ready(function() {
$("#class").change(function(){
/*dropdown post */
$.ajax({
url:"<?php echo base_url(); ?>index.php?/admin/buildDropEquipment",
data: {class: $(this).val()},
type: "POST",
success: function(data){
$("#type").html(data);
}
});
});
});
</script>
</head>
<body>
<!--machine class dropdown-->
<?php $classDrop = array('none' => 'Select One') + $classDrop; ?>
<dl>
<dt><strong><?php echo form_label('Equipment Class', 'class');?></strong></dt>
<dd>
<?php echo form_dropdown('class', $classDrop,'','class="required" id="class"'); ?>
</dd>
</dl>
<!--equipment type dropdown-->
<dl>
<dt><strong><?php echo form_label('Equipment Type', 'type');?></strong></dt>
<dd>
<select name="type" id="type">
<option value="">Select Equipment Class Above</option>
</select>
</dd>
</dl>
谁能告诉我为什么它在IE 9和8中可能无法正常工作?
因为'class'是javascript中的一个保留关键字,所以你应该把它改成class_name:
data: {class_name: $(this).val()},
这可以通过将IE 9的设置更改为兼容模式来修复IE 9。(IE 9 ->设置 -> F12 开发人员工具 ->浏览模式 ->然后选择 IE 9 兼容性)。它似乎适用于我们的 ADF 应用程序,带有级联下拉列表