bootstrap:选中单选按钮时更改表中的tr类

时间:2014-02-25 15:18:59

标签: jquery css twitter-bootstrap

我正在使用Bootstrap。当选择tr中的单选按钮时,我怎么能改变tr的类(例如class =“active”)?

<div class="table-responsive col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
    <table class="table">
      <tbody>

        <tr>
          <td>A</td>
          <td>Description A</td>
          <td><input type="radio" name="items" value="A"></td>
        </tr>
        <tr>
          <td>B</td>
          <td>Description B</td>
          <td><input type="radio" name="items" value="B"></td>
        </tr>
        <tr class="active">
          <td>C</td>
          <td>Description C</td>
          <td><input type="radio" name="items" value="C"></td>
        </tr>

      </tbody>
    </table>
</div> 

谢谢

1 个答案:

答案 0 :(得分:3)

你可以这样做:

$(":radio[name=items]").change(function() {
    $(".table tr.active").removeClass("active"); //remove previous active class
    $(this).closest("tr").addClass("active"); //add active to radio selected tr
});