我的复选框后,在codeigniter JavaScript中执行后操作后返回false值。如何保持复选框保留后检查后功能
这里是我的功能subjectid_change代码:
function subjectid_change(id, subjectid){
setValue(id, subjectid);
var field = '#ch' + id;
set_credithour(field, subjectid);
}
$("select[name^=subjectid]").change(function(){
var subjectid = $(this).val();
set_credithour($(this).parent('td').find('input'), subjectid);
$(this).parent().find('input').attr('name', 'credithour['+subjectid+']');
$(this).parent().next()find('input').attr('name', 'gradepoint['+subjectid+']');
$(this).parent().next().next().find('input').attr('name', 'cgpacalc['+subjectid+']');
});
我试图e.preventDefault();
但它阻止我要改变以前的值。 我也尝试过使用.prop("checked")
,结果仍然相同。
此代码为功能subjectid_change:
function set_credithour(field, subjectid){
$.post('<?php echo site_url('academic/ajax_get_subject_credit'); ?>', {subjectid:subjectid},
function(response){
if(response.success){
$(field).val(response.value);
} else{
alert('The subject you entered has no credit hour.');
}
}, 'json');
}
所以,我应该怎么做,如果我想保持复选框做一个$.post
检查后。
在控制器:
function ajax_get_subject_credit()
{
$subjectid = $this->input->post('subjectid');
$this->db->select('subjectid, subjectcredit');
$this->db->where('subjectid',$subjectid);
$query = $this->db->get('ref_subject');
$credithour = $query->row()->subjectcredit;
$query->free_result();
$result = $credithour;
echo json_encode(array('success' => true, 'value' => $result));
}
当我选择的对象,学分会自动填入,并点击复选框同意计算CGPA。但是,当我添加新主题后单击计算按钮时,计算过程不运行,复选框返回false。所以,我必须再次点击复选框并按下Calculate按钮才能使过程正常工作。这使得用户做两次相同的工作。如何解决这个问题?
你可以发布完整的代码,并显示演示? – Joseph 2013-04-04 03:18:27
你好像在使用JavaScript?您的发布数据位于您的PHP代码中,并确定复选框是否已选中,您将需要使用php访问发布数据。 – Jeemusu 2013-04-04 03:20:14
我已更新我的代码。 – Ae98 2013-04-04 03:31:12