2013-12-16 92 views
1

我有一系列單選按鈕,其中我只希望能夠選擇1。我有他們所有的同名,所以我認爲這會做的伎倆,但我仍然可以選擇所有四個。只允許檢查一個單選按鈕HTML

<h1>Portion</h1> 

      <input type="radio" name="portion_num" value="2" /> Two 

      <input type="radio" name"portion_num" value="4" /> Four 

      <input type="radio" name"portion_num" value="6" /> Six 

      <input type="radio" name"portion_num" value="8" /> Eight 

回答

5

它不工作的原因是因爲你的名字屬性的語法是錯誤的。

name"portion_num"應該name="portion_num"

http://jsfiddle.net/65ba8/

+0

奧普斯,謝謝! –

+0

沒問題..... –

1

將它們放在表單標籤內。

像這樣

 <form> 
     <input type="radio" name="portion_num" value="2" /> Two 

     <input type="radio" name="portion_num" value="4" /> Four 

     <input type="radio" name="portion_num" value="6" /> Six 

     <input type="radio" name="portion_num" value="8" /> Eight 
    </form> 
+0

無關的問題。 –

0

http://jsfiddle.net/

<form> 
    <input type="radio" name="portion_num" value="2" />Two 
    <input type="radio" name="portion_num" value="4" />Four 
    <input type="radio" name="portion_num" value="6" />Six 
    <input type="radio" name="portion_num" value="8" />Eight 
</form> 
相關問題