有没有办法定义要在单选按钮的HTML表单中选择的默认值?

时间:2012-01-23 06:10:00

标签: html forms radio-button radiobuttonlist

<body>
  <form>
    <input type="radio" name="amount" value="10"/> $10&#8194 
    <input type="radio" name="amount" value="25"/> $25&#8194 
    <input type="radio" name="amount" value="50"/> $50&#8194
    <input type="radio" name="amount" value="100"/> $100&#8194
    <input type="radio" name="amount" value="250"/> $250&#8194
    <input type="radio" name="amount" value="other"/> Other
  </form>
</body>

要使$ 50选项成为默认选择,我将使用哪些HTML代码?

Link to code bin demo

4 个答案:

答案 0 :(得分:13)

只需将其设置为已选中:

<body>
  <form>
    <input type="radio" name="amount" value="10"/> $10&#8194 
    <input type="radio" name="amount" value="25"/> $25&#8194 
    <input type="radio" name="amount" value="50" checked="checked" /> $50&#8194
    <input type="radio" name="amount" value="100"/> $100&#8194
    <input type="radio" name="amount" value="250"/> $250&#8194
    <input type="radio" name="amount" value="other"/> Other
  </form>
</body>

答案 1 :(得分:5)

只需添加

checked =“已检查”

在Button的声明中你想要默认选中。

答案 2 :(得分:3)

<input type="radio" name="amount" value="50" checked="checked"/>

答案 3 :(得分:0)

无需添加“已选中”:

<input type="radio" name="amount" value="50" checked />