复选框保留在页刷新时检查 [英] Checkbox Stays Checked on Page Refresh

查看:105
本文介绍了复选框保留在页刷新时检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个很简单的问题(我假设)。可能是一个转贴,但我在这里找不到答案,所以这里我们走。

This a pretty simple question (I assume). Probably a repost, but I couldn't find the answer here... so here we go.

我有一个复选框,我想默认为取消选中(除非我在我的php中另有说明)。

I have a checkbox on a page that I want to default to "unchecked" (unless I specify otherwise in my php).

当我刷新页面时,如果选中该复选框,它将保持选中状态,因为选中该复选框会通过一个功能向我的页面添加一个dom元素附在箱子上。所以问题是如果我刷新,框仍然检查,但dom元素不存在(因为我没有激活的功能,我不想,除非用户选中复选框),但框是 ALREADY

When I refresh the page, if the box was checked, it will stay checked which is no-bueno because checking the box adds a dom element to my page via a function attached to the box. So the problem is if I refresh, the box is still checked, but the dom element doesn't exist (because I haven't fired the function and I don't want to unless the user checks the check box) but the box is ALREADY checked and I end up in opposite land where UN checking the box creates my dom element and checking it removes it.

基本上,问题是...

Basically, the question is...

有没有办法默认一个复选框, ?

Is there a way to default a checkbox to unchecked without javascript?

BTW除了FF 3.5.10之外的任何浏览器,我还没有检查过(没有双关语)

BTW I haven't checked (no pun intended) in any browsers other than FF 3.5.10

推荐答案

请参阅 http:// weblogs .mozillazine.org / gerv / archives / 2006/10 / firefox_reload_behaviour.html
(第一则评论):

See http://weblogs.mozillazine.org/gerv/archives/2006/10/firefox_reload_behaviour.html (first comment):


这是这样做的目的,所以如果你点击刷新按钮你
不会失去你的工作。在Bugzilla有一个条目,
被WONTFIXed要求定期刷新,总是重置
的形式。基本上这是一个向后兼容的事情 - 每个
浏览器自NS1.0(甚至可能是Mosiac)这样做。

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.

动态生成的网页甚至重置自己,但如果
到期设置为0,并且您按下返回按钮,它将给你一个
新表单。另外,如果表单本身改变(添加或删除元素,
改变动作等),for将在重新加载时重置。我没有
测试它,但将表单名称设置为随机的(假设你
不需要名称为js访问)可能只是工作。在PHP中像>一样。

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)?

这篇关于复选框保留在页刷新时检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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