【问题标题】:radio_buttons with jquery带有 jquery 的单选按钮
【发布时间】:2013-08-26 09:32:29
【问题描述】:

编辑:

这是问题/问题
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> 

【问题讨论】:

  • 以什么方式不能按应有的方式工作,请提供的不仅仅是代码
  • 想要它做什么?它没有做什么?
  • 抱歉,更新问题

标签: jquery jquery-ui radio-button


【解决方案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 不起作用

【讨论】:

    【解决方案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> 
    

    【讨论】:

      【解决方案3】:

      试试这个小提琴:需要把radio按钮inside div和设置dividradio

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

      【讨论】:

        猜你喜欢
        • 2011-10-05
        • 2012-09-23
        • 2015-06-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多