单选框未重置为“已选中”火狐浏览器中的状态

发布于 2024-12-11 17:46:06 字数 897 浏览 0 评论 0原文

我不明白为什么我的单选框表单无法在 Firefox 7.0.1 中工作,但在 IE、Chrome 和 Safari 中工作正常。问题是“选中”的单选框没有重置为 HTML 显示的内容。

例如,如果我将温度设置从“f”更改为“c”并按“选择”,则操作脚本会看到正确的值。然后我按 FF 中的“返回”并刷新窗口,“c”仍处于选中状态。如前所述,这在其他浏览器中可以按预期工作,但在 FF 中则不然。

我很难相信这个基本的东西在 FF 中被破坏了,但 HTML 是简单的。

——杰夫

    <form name="form1" method="POST" action="weather_uom_set.php">        
    <h3>Precipitation</h3>
    <input type="radio" name="precip" value="in" checked="checked"/> Inches (")<br/>
    <input type="radio" name="precip" value="mm" /> Millimeters (mm)<br/>
    <h3>Temperature</h3>
    <input type="radio" name="temp" value="f" checked="checked"/> Fahrenheit (&deg;f)<br/>
    <input type="radio" name="temp" value="c" /> Celsius (&deg;c)<br/>
    <input type="submit" value="Submit" />
    </form>

I'm lost as to why my radio box form isn't working in Firefox 7.0.1, but works fine in IE, Chrome and Safari. The problem is that the radio boxes which are "checked" aren't resetting to what the HTML shows.

For example, if I change the temperature setting from "f" to "c" and and press Select, the action script sees the correct values. I then press Back in FF and refresh the window, "c" is still selected. As stated, this works as expected in other browsers, but not in FF.

I'm having a hard time believing that something this basic is broken in FF, but the HTML is straight forward.

-- Geoff

    <form name="form1" method="POST" action="weather_uom_set.php">        
    <h3>Precipitation</h3>
    <input type="radio" name="precip" value="in" checked="checked"/> Inches (")<br/>
    <input type="radio" name="precip" value="mm" /> Millimeters (mm)<br/>
    <h3>Temperature</h3>
    <input type="radio" name="temp" value="f" checked="checked"/> Fahrenheit (°f)<br/>
    <input type="radio" name="temp" value="c" /> Celsius (°c)<br/>
    <input type="submit" value="Submit" />
    </form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

許願樹丅啲祈禱 2024-12-18 17:46:06

这可能是因为 Firefox 会记住以前的表单提交值,这可能会覆盖您在 HTML 中定义的任何默认选择。另外,即使您没有在这里说明,我想指出 Javascript 也可以覆盖默认的 HTML 行为,因此,如果您确实运行了脚本,请确保它也没有设置/覆盖默认值。

It may be because Firefox is remembering the previous form submission values, which can override any default choices you've defined in your HTML. Also, even though you haven't stated it here, I'd like to point out that Javascript can also override default HTML behavior as well, so if you do have a script running, make sure it also isn't setting/overriding a default value.

ま柒月 2024-12-18 17:46:06

是的,这个基本原则在 Firefox 中被破坏了:https://stackoverflow.com/a/8779735/370290

Yes, this basic is broken in Firefox: https://stackoverflow.com/a/8779735/370290

Smile简单爱 2024-12-18 17:46:06

我最初犯了一个错误,在“否”框中设置checked = false,而不是在“是”框中设置checked =“true”。

但是,您可能会考虑我提出的类似修复,以确保您在页面加载时获得所需的值:

<input type="radio" name="mybox" id="mybox_yes" value="1">
<input type="radio" name="mybox" id="mybox_no" checked="checked" value="0">

<script>

    var mybox = 0; // value 1 or 0 inserted with server side script

    if(mybox == 1){
        var fix_checkbox = function(){
            document.getElementById("mybox_yes").checked=true;
        };
    }
    else
    {
        var fix_checkbox = function(){
        document.getElementById("mybox_no").checked=true;
        };
    }

    setTimeout(fix_checkbox,1000);

</script>

最好在逻辑服务器端进行操作,然后仅输出您想要的行:

<script>
    setTimeout(function(){document.getElementById("mybox_no").checked=true;},1000);
</script>

I originally made the mistake of setting checked=false on the "no" box instead of setting checked="true" on the "yes" box.

However, you might consider a similar fix I came up with to ensure that you get the value you want when the page loads:

<input type="radio" name="mybox" id="mybox_yes" value="1">
<input type="radio" name="mybox" id="mybox_no" checked="checked" value="0">

<script>

    var mybox = 0; // value 1 or 0 inserted with server side script

    if(mybox == 1){
        var fix_checkbox = function(){
            document.getElementById("mybox_yes").checked=true;
        };
    }
    else
    {
        var fix_checkbox = function(){
        document.getElementById("mybox_no").checked=true;
        };
    }

    setTimeout(fix_checkbox,1000);

</script>

It might be better to do the logic server side then only output the line you want:

<script>
    setTimeout(function(){document.getElementById("mybox_no").checked=true;},1000);
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文