单选框未重置为“已选中”火狐浏览器中的状态
我不明白为什么我的单选框表单无法在 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 (°f)<br/>
<input type="radio" name="temp" value="c" /> Celsius (°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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能是因为 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.
是的,这个基本原则在 Firefox 中被破坏了:https://stackoverflow.com/a/8779735/370290
Yes, this basic is broken in Firefox: https://stackoverflow.com/a/8779735/370290
我最初犯了一个错误,在“否”框中设置checked = false,而不是在“是”框中设置checked =“true”。
但是,您可能会考虑我提出的类似修复,以确保您在页面加载时获得所需的值:
最好在逻辑服务器端进行操作,然后仅输出您想要的行:
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:
It might be better to do the logic server side then only output the line you want: