HTML 默认拒绝检查单选按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15009597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:47:54  来源:igfitidea点击:

HTML refuses to check radio button by default?

htmlforms

提问by jovan

This looks like a really basic question and I've created dozens of forms, but I just can't see what the problem is here.

这看起来是一个非常基本的问题,我已经创建了几十个表单,但我看不出这里有什么问题。

I have these two radio buttons:

我有这两个单选按钮:

<input type='radio' class='free atype' value='0' name='dutch' checked='checked'/> Free<br/>
<input type='radio' class='paid atype' value='1' name='dutch' /> Paid

Obviously the first one should be checked by default.

显然,默认情况下应该检查第一个。

However, when I check the second one and then refresh the page, the second radio remains checked. I know this is wrong behavior, but I can't for the life of me see what I'm doing wrong.

但是,当我检查第二个然后刷新页面时,第二个无线电保持选中状态。我知道这是错误的行为,但我一辈子都看不到我做错了什么。

I'm trying this on Firefox.

我正在 Firefox 上尝试这个。

回答by Musa

This is what's called auto complete, you can try to turn it off by adding the autocomplete="off"property to your inputs

这就是所谓的自动完成,您可以尝试通过将autocomplete="off"属性添加到您的输入来关闭它

<input type='radio' class='free atype' value='0' name='dutch' checked='checked' autocomplete="off"/> Free<br/>
<input type='radio' class='paid atype' value='1' name='dutch' autocomplete="off"/> Paid

You can also put it on the <form>the elements are in.

你也可以把它放在<form>元素所在的地方。

回答by satheesh kumar

Use Autocomplete="Off"as one of the properties in a tag

使用Autocomplete="Off"作为标记中的属性之一

that will make some sense for that code.

这对该代码有意义。