无法在HTML中的单选按钮之间进行选择?

med*_*pir 4 html

我有以下表格代码,但我不能在IE中选择卖出收音机,我可以在谷歌浏览器中同时选择两个收音机.

<form method="post" action="dothemath.php" style="width: 403px" class="style1">
<input type="radio" id="rdobuy" style="width: 20px; height: 21px;" checked="checked"/>
<label>Buy</label>
<input type="radio" id="rdosell" style="width: 20px; height: 21px;"/>
<label >Sell</label>
</form>
Run Code Online (Sandbox Code Playgroud)

有什么我想念的东西......?

Que*_*tin 13

您的单选按钮没有name属性.他们需要它们有两个原因.

  1. 具有相同名称将一组单选按钮分组到单个无线电组中
  2. 该名称用于生成要提交给服务器的表单数据

您还需要value说明提交的数据.

顺便说一句,你的<label>s无用,因为它们与任何控件无关.它们需要一个forid它们要关联的控件具有相同值的属性.

<form method="post" action="dothemath.php">

    <input type="radio" id="rdobuy" name="foo" value="buy" checked="checked"/>
    <label for="rdobuy">Buy</label>

    <input type="radio" name="foo" value="sell" id="rdosell" />
    <label for="rdosell">Sell</label>

</form>
Run Code Online (Sandbox Code Playgroud)