我有複選框,動態生成,當複選框被選中時,onchange方法工作正常,我的函數也被調用時,用戶未選中框onchange方法調用我的意圖功能的問題是,當框被選中時,頁面的一部分變爲活動狀態,這是很好的,但是當用戶取消選中該複選框時,頁面的該部分再次變爲活動狀態,並且複選框「checked」的值保持爲yes第一次檢查。有沒有辦法檢測用戶何時選擇取消選中,以便頁面的活動部分變爲非活動狀態。複選框問題(使用post和onchange)
我可以發送複選框狀態,而不必在表單中提交。是否需要提交郵寄才能工作?我必須爲此使用Java腳本嗎?
我想這我遇到的問題
<script type="text/jscript">
//this funciton will be called when user checks a check box.
function edit(){
//get selected category from the form
//var formName = 'choose';
//var Category = document[formName]['choose'].value;
//check if browser suports ajax
var xmlhttp = null;
if(typeof XMLHttpRequest != 'udefined'){
xmlhttp = new XMLHttpRequest();
}
else if(typeof ActiveXObject != 'undefined'){
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
else
throw new Error('You browser doesn\'t support ajax');
//open connection with activateImages.php to recieve the active images as an acho
xmlhttp.open("GET", "activateImages.php",true);
//echeck if ready to recieve
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4)
window.activate(xmlhttp);
};
xmlhttp.send(null);
}
//recieve the active images then insert them in the specified location of the page.
function activate(xhr){
if(xhr.status == 200){
document.getElementById('images').innerHTML = xhr.responseText;
}
else
throw new Error('Server has encountered an error\n'+
'Error code = '+xhr.status);
}
</script>
你可以使用jQuery嗎? –
[使用onchange複選框]的可能重複(http://stackoverflow.com/questions/13143337/check-box-using-onchange) –