radio_buttons与jquery

时间:2013-08-23 10:50:30

标签: jquery jquery-ui radio-button

编辑:

以下是问题/问题
Jquery按钮在第一个示例(场地)中工作(以jquery样式显示格式,根据jquery documentation中的示例)并且在第二个示例中不起作用(不显示以jquery样式格式化)(无线电)。

我一直试图让jquery按钮工作,但我似乎无法做到。

我一直在this question工作,并改编了jfiddle

我确信它一定是我遗漏的一件小事 - 但为什么这段代码有效:

<fieldset class="filter_form_fieldset venues">
    <legend class="filter_form_fieldset_legend">Choose a venue type:</legend>
    <input type="checkbox" name="venuetypes[]" id="venue-1" />
    <label for="venue-1">Venue 1</label>
    <input type="checkbox" name="venuetypes[]" id="venue-2" />
    <label for="venue-2">Venue 2</label>
    <input type="checkbox" name="venuetypes[]" id="venue-3" />
    <label for="venue-3">Venue 3</label>
</fieldset>

并且此代码没有?

<tr>
  <td class="goal_row">goal 1: </td> 
  <td id="radio">
    <input id="score_1_1" name="score_1" type="radio" value="1" />
    <label for="score_1">1</label>
    <input id="score_1_2" name="score_1" type="radio" value="2" />
    <label for="score_1">2</label>
    <input id="score_1_3" name="score_1" type="radio" value="3" />
    <label for="score_1">3</label>
    <input id="score_1_4" name="score_1" type="radio" value="4" />
    <label for="score_1">4</label>
    <input id="score_1_5" name="score_1" type="radio" value="5" />
    <label for="score_1">5</label>
  </td>
</tr> 

3 个答案:

答案 0 :(得分:2)

FIDDLE

将无线电放入div中,并将for值从name改为id

<tr>


<td class="goal_row">goal 1: </td> 
  <td>
      <div id="radio">
          <input id="score_1_1" name="score_1" type="radio" value="1" />
            <label for="score_1_1">1</label>
            <input id="score_1_2" name="score_1" type="radio" value="2" />
            <label for="score_1_2">2</label>
            <input id="score_1_3" name="score_1" type="radio" value="3" />
            <label for="score_1_3">3</label>
            <input id="score_1_4" name="score_1" type="radio" value="4" />
            <label for="score_1_4">4</label>
            <input id="score_1_5" name="score_1" type="radio" value="5" />
            <label for="score_1_5">5</label>
      </div>
  </td>
</tr> 

答案 1 :(得分:0)

试试这个小提琴:需要放radio按钮inside div并设置div idradio

http://jsfiddle.net/DZx3z/61/

答案 2 :(得分:-1)

好吧,我明白了。它和id问题将下面的代码放在你的代码中,这将有效 检查这个小提琴http://jsfiddle.net/DZx3z/62/

<tr>
  <td class="goal_row">goal 1: </td> 
  <td>
    <div id="radio">
    <input id="score_1_1" name="score_1" type="radio" value="1" />
    <label for="score_1_1">1</label>
    <input id="score_1_2" name="score_1" type="radio" value="2" />
    <label for="score_1_2">2</label>
    <input id="score_1_3" name="score_1" type="radio" value="3" />
    <label for="score_1_3">3</label>
    <input id="score_1_4" name="score_1" type="radio" value="4" />
    <label for="score_1_4">4</label>
    <input id="score_1_5" name="score_1" type="radio" value="5" />
    <label for="score_1_5">5</label>
    </div>
  </td>
</tr> 

您的代码中存在什么问题:

这是一个小问题,您试图将name attr value放入for attr of label,这就是为什么不起作用for attr works for id val