这里我在html中拖动单选按钮,但当我选择单选按钮一,然后当我选择另一个单选按钮时,第二个总是选择我想要的地方,当我选择1单选按钮,然后其他将不会被选中这里是图像和代码
图像
码
<tr>
<td class="style10"><label>Subject Knowledge: </label></td>
<td class="style10">
<input id="Radio1" type="radio" /><span>1</span>
<input id="Radio2" type="radio" /><span>2</span>
<input id="Radio3" type="radio" /><span>3</span>
<input id="Radio4" type="radio" /><span>4</span>
<input id="Radio5" type="radio" /><span>5</span>
<p>Please tick the level of subject knowledge (1 = low to 5 = high)</p></td>
</tr>
有什么帮助吗?
答案 0 :(得分:3)
为所有单选按钮指定相同的名称。 试试这个
<tr>
<td class="style10"><label>Subject Knowledge: </label></td>
<td class="style10">
<input id="Radio1" type="radio" name="somename" /><span>1</span>
<input id="Radio2" type="radio" name="somename"/><span>2</span>
<input id="Radio3" type="radio" name="somename"/><span>3</span>
<input id="Radio4" type="radio" name="somename"/><span>4</span>
<input id="Radio5" type="radio" name="somename"/><span>5</span>
<p>Please tick the level of subject knowledge (1 = low to 5 = high)</p></td>
</tr>
&#13;
答案 1 :(得分:1)
您应该在单选按钮上添加name
属性。
如果两个单选按钮具有相同的名称,则只能选择一个。
<tr>
<td class="style10"><label>Subject Knowledge: </label></td>
<td class="style10">
<input id="Radio1" name="myName" type="radio" /><span>1</span>
<input id="Radio2" name="myName" type="radio" /><span>2</span>
<input id="Radio3" name="myName" type="radio" /><span>3</span>
<input id="Radio4" name="myName" type="radio" /><span>4</span>
<input id="Radio5" name="myName" type="radio" /><span>5</span>
<p>Please tick the level of subject knowledge (1 = low to 5 = high)</p></td>
</tr>
修改强>
为了改善您的代码,您还可以:
label
标记以启用标签上的选择value
属性以下是一个例子:
<td class="style10"><label>Subject Knowledge: </label></td>
<td class="style10">
<label>
<input type="radio" name="myName" value="1" />
<span>1</span>
</label>
<label>
<input type="radio" name="myName" value="2" />
<span>2</span>
</label>
<label>
<input type="radio" name="myName" value="3" />
<span>3</span>
</label>
<label>
<input type="radio" name="myName" value="4" />
<span>4</span>
</label>
<label>
<input type="radio" name="myName" value="5" />
<span>5</span>
</label>
<p>Please tick the level of subject knowledge (1 = low to 5 = high)</p>
</td>
答案 2 :(得分:0)
要制作单选按钮组以仅选择一个,您必须为所有单选按钮指定相同的名称,如下所示:
<tr>
<td class="style10"><label>Subject Knowledge: </label></td>
<td class="style10">
<input id="Radio1" name="rdSubKnowledge" type="radio" /><span>1</span>
<input id="Radio2" name="rdSubKnowledge" type="radio" /><span>2</span>
<input id="Radio3" name="rdSubKnowledge" type="radio" /><span>3</span>
<input id="Radio4" name="rdSubKnowledge" type="radio" /><span>4</span>
<input id="Radio5" name="rdSubKnowledge" type="radio" /><span>5</span>
<p>Please tick the level of subject knowledge (1 = low to 5 = high)</p>
</td>
</tr>
答案 3 :(得分:0)
You should specify same name for the radio button group
for example:
<div>
<input name="Sport" type="radio" /><span>Basketball</span>
<input name="Sport" type="radio" /><span>Volleyball</span>
<input name="Sport" type="radio" /><span>Rugby</span>
<input name="Sport" type="radio" /><span>Football</span>
<input name="Sport" type="radio" /><span>Tennis</span>
</div>