这是一个非常简单的问题(我假设)。可能是转发,但我在这里找不到答案...所以我们开始吧。
我在页面上有一个复选框,我想将其默认为“未选中”(除非我在我的 php 中另外指定)。
当我刷新页面时,如果选中该框,它将保持选中状态,这是 no-bueno,因为选中该框会通过附加到该框的函数向我的页面添加一个 dom 元素。所以问题是,如果我刷新,该框仍处于选中状态,但 dom 元素不存在(因为我没有触发该功能,除非用户选中该复选框,否则我不想这样做)但是该框是ALREADY 选中,我最终到达了相反的地方,UN 选中该框创建了我的 dom 元素,选中它删除了它。
基本上,问题是...
有没有办法在没有 javascript 的情况下将复选框默认为未选中?
顺便说一句,除了 FF 3.5.10,我还没有在任何浏览器中检查过(没有双关语)
最佳答案
参见 http://weblogs.mozillazine.org/gerv/archives/2006/10/firefox_reload_behaviour.html (第一条评论):
It’s done that way on purpose so if you tap the refresh button you don’t lose your work. There’s an entry in Bugzilla somewhere that’s been WONTFIXed asking for a regular refresh to always reset the form entirely. Basically it’s a backwards-compatibility thing — every browser since NS1.0 (maybe even Mosiac) has done that.
Dynamically-generated pages don’t even reset themselves, though if the expiration is set to 0 and you hit the back button it will give you a fresh form. Also, if the form itself changes (add or remove elements, change the action, etc.) the for will reset on a reload. I haven’t tested it, but setting the form name to something random (assuming you don’t need the name for JS access) might just work. Like ”> in PHP.
As you said, forcing a refresh clears the form, and resetting it does too. Would something like do what you want (again, not tested)?
关于html - 复选框在页面刷新时保持选中状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3176155/