最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Keep single radio button unchecked on page load - Stack Overflow

programmeradmin8浏览0评论

I have a radio button in my html:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <input type="radio" name="r"/>
</body>
</html>

If I check it, and reload the page (Firefox 20.0.1) it will stay checked. But if I clear the cache (ctrl+f5) the button gets unchecked again.

Is there any way to make it consistent so that it always unchecks itself when the page is refreshed? Or do I need to involve javascript? I've tried with and without the name property.

PS. I wasn't able to make a fiddle. Try it on a local file in order to reproduce it.

I have a radio button in my html:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <input type="radio" name="r"/>
</body>
</html>

If I check it, and reload the page (Firefox 20.0.1) it will stay checked. But if I clear the cache (ctrl+f5) the button gets unchecked again.

Is there any way to make it consistent so that it always unchecks itself when the page is refreshed? Or do I need to involve javascript? I've tried with and without the name property.

PS. I wasn't able to make a fiddle. Try it on a local file in order to reproduce it.

Share Improve this question asked May 7, 2013 at 9:09 JohanJohan 35.2k62 gold badges188 silver badges305 bronze badges 4
  • AFAIK there's no way to do this crossbrowser without JS...I may be wrong tho. – elclanrs Commented May 7, 2013 at 9:11
  • @elclanrs I was afraid that this es down to individual browser behaviour... – Johan Commented May 7, 2013 at 9:13
  • I think, you have to use javascript for this. clearing cache is a bad practice, as most of the sites depend on it. – dreamweiver Commented May 7, 2013 at 9:14
  • 2 Here is a fiddle that reproduced the problem in my Firefox. – ValarDohaeris-fuck-OpenAI Commented May 7, 2013 at 9:17
Add a ment  | 

1 Answer 1

Reset to default 7

You can set autoplete="off":

<input type="radio" name="r" autoplete="off" />

Please check this documentations:

Mozilla Dev

W3C

And working example: http://fiddle.jshell/2fAuY/2/show/ (thank you @ValarDohaeris for fiddle)

发布评论

评论列表(0)

  1. 暂无评论