如何显式设置复选框未选中
我有一个带有过渡文档类型的 xhtml 页面,其中有一个复选框,我希望在加载后取消选中该复选框。没有 JavaScript!在 Firefox 3.5(例如,可能还有其他浏览器)中,用户可以检查输入,而不是重新加载页面并检查输入。我怎样才能克服这种行为?
I have a xhtml page with transitional doctype having a checkbox that I want to be unchecked after loading. No JavaScript! In Firefox 3.5 (for instance, there may be other browsers) user can check input, than reload page and get input checked. How can I overcome this behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用
另请查看 为什么复选框保持选中状态重新加载页面时?
Use
Also have a look at Why does the checkbox stay checked when reloading the page?
仅使用 HTML 无法改变文档的状态。您所能做的就是设置或不设置
checked="checked"
。您需要 JavaScript 或服务器端语言来确定是否应设置该属性。
You can't do much to change a document's state with HTML alone. All you can do is set
checked="checked"
or not.You need either JavaScript or a server side language to determine whether that attribute should be set or not.
如果没有 JavaScript,你就做不到。这是 Firefox 特有的行为,即使您可以显式强制“未选中”状态(您不能,因为缺少
checked
已经意味着这一点),也会发生这种行为。据我所知,唯一的非 Javascript 方法是在每次请求时在服务器端重命名表单元素,这样 FF 就没有机会存储该值。
You can't, not without JavaScript. This is Firefox specific behaviour which would occur even if you could explicitly force an "unchecked" state (which you can't, because the absence of
checked
already means that.)The only non-Javascript way that I know of is to rename the form element on server-side on every request so FF has no chance of storing the value.
要明确地将复选框设置为未选中,以下方法对我有用:
To explicitly set the checkbox to unchecked, the following worked for me:
<input type="checkbox" unchecked>
尝试将以下代码放入您的代码中:
当页面启动或刷新时,它将被取消选中。
Try to put in your code this:
It will be unchecked when the page starts or refreshes.