Tho*_*mas 1 html css forms jquery
当用户按下按钮时,我需要更改包含单选按钮的div的bg颜色.我正在使用jquery - 所以它似乎应该有一些简单的方法来实现这一点.我的html设置如下:
<div class="sales_box">
<table>
<tr>
<td class="radio_cell"><input type="radio"></td>
</tr>
</table>
</div>
<div class="sales_box">
<table>
<tr>
<td class="radio_cell"><input type="radio"></td>
</tr>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
只需处理单选按钮的更改事件,然后使用closest()jQuery 的方法:
$(document).ready(function(){
$('input:radio').change(function(){
$(this).closest('div').css('background-color', 'red');
});
});
Run Code Online (Sandbox Code Playgroud)
正如redsquare所说,你不应该真正设置内联css.你应该使用toggleclass函数.我只是用css函数作为例子.
| 归档时间: |
|
| 查看次数: |
5508 次 |
| 最近记录: |