checked =“选中”单选按钮似乎无法正常工作

时间:2017-06-15 08:59:39

标签: html radio-button checked

我正在尝试默认使用HTML设置单选按钮。在浏览器中我有:

<label><input type="radio" checked="checked" name="optradio" i="1">Nein</label>

但未选中单选按钮。

我做错了什么?

截图: enter image description here

2 个答案:

答案 0 :(得分:1)

My bad. I had another radio button later on the page that was also checked and had the same name="optradio". It would uncheck the first no matter where it is ~~:-|

$(function() {
  $("div").html( `
    <div class="radio radio1">
    <label><input type="radio" checked="checked" name="optradio" i="1">Nein</label>
    </div>

    <div class="radio radio3">
    <label><input type="radio" checked="checked" name="optradio" i="3">2</label>
    </div>
` )
;  
})

See Codepen: https://codepen.io/lafisrap/pen/yXVyWR?editors=1010

答案 1 :(得分:-1)

enter image description here试试这个,

<label><input type="radio" name="optradio" checked>Nein</label>

我们也可以使用单一检查而不是使用checked =“checked”。

如果您需要进一步澄清,请阅读并试试。 https://www.w3schools.com/tags/att_input_checked.asp