使用Jquery在下拉列表行中返回不同的值
我有一行复选框,其中包含与之关联的下拉列表。如何在所选复选框的相应下拉列表中返回值使用Jquery在下拉列表行中返回不同的值,jquery,html,Jquery,Html,我有一行复选框,其中包含与之关联的下拉列表。如何在所选复选框的相应下拉列表中返回值 HTML 公元前 1. 2. 3. 1. 2. 3. 1. 2. 3. 您可以使用同级()以选择为目标,或转到父级TD并使用查找()。另外,不推荐使用live(),请改用on() 如果使用toggleClass()可以删除if($(this).hasClass('checked')) API参考资料: 我更改了您的示例您缺少结束标记。。而ID不应该以数字开头。您还应该使用包装TH,使用的表体应该使用p
HTML
公元前
1.
2.
3.
1.
2.
3.
1.
2.
3.
您可以使用同级()
以选择为目标,或转到父级TD
并使用查找()。另外,不推荐使用live()
,请改用on()
如果使用toggleClass()
可以删除if($(this).hasClass('checked'))
API参考资料:
我更改了您的示例您缺少结束标记。。而ID
不应该以数字开头。您还应该使用
包装TH
,使用
的表体应该使用prop()
方法在jQuery 1.6及更高版本中检查
$('input[name=options]').live('click', function() {
if($(this).hasClass('checked'))
{
$(this).removeClass('checked');
}else{
$(this).addClass('checked');
}
});
<table id="test" summary="test">
<th>A</th> <th>B</th><th>C</th>
<tr>
<td><input type="checkbox" name="options" id="1" value="500">
<select class="my_select">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option></td>
<td><input type="checkbox" name="options" id="2" value="500">
<select class="my_select">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option></td>
<td><input type="checkbox" name="options" id="3" value="500">
<select class="my_select">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option></td>
</tr>
</table>
$(document).on('click', 'input[name=options]', function() {){
/* "this" within the handler refers to current input*/
var selectVal= $(this).siblings('select').val();
/* OR */
var selectVal= $(this).parent().find('select').val();
/* second argument determines whether to add or remove*/
$(this).toggleClass('checked', this.checked);
});
$('input[type=checkbox]').click(function() {
if($(this).attr('checked'))
alert(
'value of combo ' +
$(this).attr('id') + ' is ' +
$(this).next('.my_select').val()
);
});