刷新页面后,单选按钮可以为空吗 [英] Can radio buttons be empty after refreshing a page

查看:55
本文介绍了刷新页面后,单选按钮可以为空吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单中有两个单选按钮.现在我发现,在某些浏览器(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.

这篇关于刷新页面后,单选按钮可以为空吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆