简体   繁体   English

刷新页面后,单选按钮可以为空吗

[英]Can radio buttons be empty after refreshing a page

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. 现在,我发现在某些浏览器(firefox和google chrome)中,如果刷新表单,则在刷新之前选择了一个单选按钮,然后在刷新之后仍然选择了该单选按钮。 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: 以下是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 code: 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>

It could be browsers caching the page. 可能是浏览器缓存页面。 Try setting checked=false on both radio buttons to begin with. 首先尝试将两个单选按钮都设置为checked=false If that does not work, have a look at page cache options. 如果这样不起作用,请查看页面缓存选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM