我有复选框动态生成,当复选框被选中onchange方法工作正常,我的功能也被调用时,该框没有被用户选中onchange方法调用我的预期功能问题是当选中该框时,页面的一部分变为活动状态,这很好,但是当用户取消选中该复选框时,该页面的该部分再次变为活动状态,并且复选框“checked”的值在第一次后保持为yes被检查。有没有办法检测用户何时选择取消选中,以便页面的活动部分变为非活动状态。复选框使用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>
'='!='=='... –
您应该发布代码和伪代码组合的代码(包括JavaScript),因为有太多的错误,所以几乎不可能说问题是什么。 – jeroen
我们需要查看您的javascript函数edit(),以便能够帮助您充分发挥我们的能力。 – SamHuckaby