单选按钮不检查选中的按钮

Abh*_*ash 0 html

即使是第二台收音机也检查了它没有检查,并检查最后一台

<div>
  <input type="radio" id="bed_room_1" name="room[bed_room]" value="1" checked="false" />
  <label for="bed_room_1">1</label>
  </input>

  <input type="radio" id="bed_room_2" name="room[bed_room]" value="2" checked="true" />
  <label for="bed_room_2">2</label>
  </input>
  <input type="radio" id="bed_room_3" name="room[bed_room]" value="3" checked="false" />
  <label for="bed_room_3">3</label>
  </input>
  <input type="radio" id="bed_room_4" name="room[bed_room]" value="4" checked="false" />
  <label for="bed_room_4">4+</label>
  </input>
</div>
Run Code Online (Sandbox Code Playgroud)

Codepen链接codepen

dev*_*rCK 5

签入单选按钮不是接受true或false 的属性.这是一个属性.所以要么检查将工作或检查="已检查"将起作用

<input type="radio" id="bed_room_2" name="room[bed_room]" value="2" checked />
<label for="bed_room_2">2</label>
Run Code Online (Sandbox Code Playgroud)

了解HTML中的更多 属性和属性

差异b/w属性和属性

http://lucybain.com/blog/2014/attribute-vs-property/

  • _"所以只有__checked__才能工作"_ - 而不是"only",`checked ="checked"`也是允许的(http://www.w3.org/TR/html5/infrastructure.html#boolean-attribute) - 和_necessary_,如果想要编写与XML兼容的代码,因为它不允许没有值的"独立"属性. (2认同)