刷新页面后,单选按钮可以为空吗
我的表单中有两个单选按钮.现在我发现,在某些浏览器(firefox和google chrome)中,如果您刷新表单,则在刷新之前选择了一个单选按钮,然后在刷新之后仍然选择了该单选按钮.我想知道有没有一种方法可以使用javascript代码说页面重新加载或刷新时不应该选择任何单选按钮,或者这完全取决于浏览器吗?
I have two radio buttons in my form. Now what I found out is that in some browsers (firefox and google chrome) if you refresh the form, is a radio button was selected before the refresh, then after the refresh the radio button is still selected. I want to know is there a way by using javascript code to be able to say no radio buttons should be already selected when page reloads or refreshes or does it all depend on browser?
以下是javascript中单选按钮的代码:
Below is code for radio buttons in javascript:
var btnRadioO = document.getElementsByName("weightChoice");
var isbtnRadioChecked = false;
for(i=0; i < btnRadioO.length; i++){
if(btnRadioO[i].checked){
isbtnRadioChecked = true;
}
}
if(!isbtnRadioChecked) {
errRadioMsgO.innerHTML = "Please Select whether you want to include a Total Weight for your Session or Not";
tblWeightO.style.display = "none";
isDataValid = false;
}else if(btnRadioO[0].checked==true && weightO.value == 0){
errRadioMsgO.innerHTML = "";
errWeightMsgO.innerHTML = "You are including Weight so it Must be More Than 0";
isDataValid = false;
}else if(btnRadioO[1].checked==true){
errRadioMsgO.innerHTML = "";
errWeightMsgO.innerHTML = "";
tblWeightO.style.display = "none";
}else{
errRadioMsgO.innerHTML = "";
errWeightMsgO.innerHTML = "";
}
HTML代码:
<table>
<tr>
<th>6: Provide a Total Weight for your Session</th>
<td><input type="radio" name="weightChoice" value="yes" onClick="getWeight()"/> Yes</td>
<td><input type="radio" name="weightChoice" value="No" onClick="getWeight()"/> No</td>
</tr>
</table>
可能是浏览器在缓存页面.首先尝试在两个单选按钮上设置checked=false
.如果这样不起作用,请查看页面缓存选项.
It could be browsers caching the page. Try setting checked=false
on both radio buttons to begin with. If that does not work, have a look at page cache options.