我有动态生成的复选框,当复选框被选中时,onchange方法工作正常并且我的函数也被调用,当用户取消选中该框时,onchange方法调用我的预期函数问题是当复选框被选中时页面变为活动状态,这很好,但是当用户取消选中复选框时,页面的该部分再次变为活动状态,并且复选框“已选中”的值在第一次被选中后保持为是。有没有办法检测用户何时选择取消选中以使页面的活动部分变为非活动状态。
她是我的密码
echo '<table width="85%" border="1" cellpadding="0"; cellspacing="0" align="center">
<tr>
<th width="23%" height="44" scope="col" align="left"> '.$query_rows['categoryTopic'].' <br><br><br></th>
<th width="24%" scope="col">'.$Count.'</th>
<th width="25%" scope="col"> 0 </th>
<th width="28%" scope="col"> <form name = "choose" method="post" action="activateImages.php">
<input type="checkbox" value= "5" onChange="window.edit()" </form></th>
</tr>
</table>';
}
?>
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>