我正在使用带有PHP Codeigniter的Bootstrap。我的表格中有几个复选框。如果我单击一个复选框,其他一些复选框将被禁用并呈灰色。但在表单提交验证后,那些已禁用或不活动的复选框将变为活动状态。失去灰色。但我不想要这种行为。
HTML部分:
<div class="align">
<label> <input type="checkbox" size="2" name="M1500" value="01" <?php echo set_checkbox('M1500', '01' ); ?> class="chec1_1500 checker1510"> No </label>
<label> <input type="checkbox" size="2" name="M1500" value="02" <?php echo set_checkbox('M1500', '02' ); ?> class="chec1_1500 " > Yes</label>
<label> <input type="checkbox" size="2" name="M1500" value="03" <?php echo set_checkbox('M1500', '03' ); ?> class="chec1_1500 checker1510" > Not assessed</label>
<label> <input type="checkbox" size="2" name="M1500" value="NA" <?php echo set_checkbox('M1500', 'NA' ); ?> class="chec1_1500 checker1510" > Patient does not have diagnosis of heart failure</label>
</div>
<div class="align">
<label> <input type="checkbox" name="M1510_1" class="check_1510" Size="1" <?php echo set_checkbox('M1510_1', '1' ); ?> value="1" onclick="SetAllCheckBoxes('myForm', 'myCheckbox1',this.checked);" style="padding-right:20px;" value="1" > No action taken</label>
<label> <input type="checkbox" name="M1510_2" class="check_1510" Size="1" <?php echo set_checkbox('M1510_2', '2' ); ?> id="myCheckbox1" value="2" > Patient’s Physician</label>
<label> <input type="checkbox" name="M1510_3" class="check_1510" Size="1" <?php echo set_checkbox('M1510_3', '3' ); ?> id="myCheckbox1" value="3" > Patient </label>
<label> <input type="checkbox" name="M1510_4" class="check_1510" Size="1" <?php echo set_checkbox('M1510_4', '6' ); ?> id="myCheckbox1" value="6" > Obtained </label>
</div>
Java脚本:
$('input.chec1_1500').on('change', function() { // 1 checked others disable in same
$('input.chec1_1500').not(this).prop('disabled', this.checked);
$('input.chec1_1500').not(this).prop('checked', false);
});
$('.checker1510').change(function() { // To disable 1510
$('input.check_1510').not(this).prop('checked', false);
$('.check_1510').not(this).prop('disabled', this.checked);
});
控制器:
public function transfer_add(){
sleep(1);
$data=array();
$this->form_validation->set_rules('M1500','','callback_check_1500');
$this->form_validation->set_rules('M1510_1','','');
$this->form_validation->set_rules('M1510_2','','');
$this->form_validation->set_rules('M1510_3','','');
$this->form_validation->set_rules('M1510_4','','');
if($this->form_validation->run()==FALSE){
$this->load->view('transfer');
} else {
$data['M1500 '] =$this->input->post('M1500');
$data['M1510_1'] =$this->input->post('M1510_1');
$data['M1510_2'] =$this->input->post('M1510_2');
$data['M1510_3'] =$this->input->post('M1510_3');
$data['M1510_4'] =$this->input->post('M1510_4');
$this->groups_model->add_transfer($data);
redirect('transfer/index');
}
}