Checkbox Stays Checked on Page Refresh

前端 未结 3 747
醉话见心
醉话见心 2020-12-19 03:18

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

I have a checkbox on a page that I want to defau

相关标签:
3条回答
  • 2020-12-19 03:23

    Sure:

    document.getElementById('my_checkbox').checked = false;
    

    Oops, I missed the part about no JS. As far as I know, Firefox retains page state on refresh, so I guess there's no other way.

    0 讨论(0)
  • 2020-12-19 03:25

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

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

    0 讨论(0)
  • 2020-12-19 03:37

    this works for ie autocomplete="off"

    0 讨论(0)
提交回复
热议问题