我的複選框後,在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