点击单选按钮,我试图按下Button文本的值。
但是在这种情况下我遇到了jquery选择器的问题
<table class="table table-striped table-bordered table-hover dataTable" id="customer_details_table" aria-describedby="sample_1_info" style="display: table;">
<thead>
<tr>
<th></th>
<th>Customer Name</th>
<th>Address</th>
<th>Contact No.</th>
<th>Email</th>
<th>Action</th>
</tr>
</thead>
<tbody class="odd gradeX">
<tr>
<td>
<label class="radio">
<input type="radio" class="bradio" id="20" name="optionsRadios1" value="option1">
</label>
</td>
<td width="20%">kiran</td>
<td width="25%">XXXXXXX</td>
<td width="20%">7654321987</td>
<td width="20%">venkatrajkiran@yahoo.com</td>
<td width="10%" align="center"> <span class="label label-success">Active</span>
</td>
</tr>
<tr>
<td>
<label class="radio">
<input type="radio" class="bradio" id="28" name="optionsRadios1" value="option1">
</label>
</td>
<td width="20%">kiran</td>
<td width="25%">XXXXXXX</td>
<td width="20%">9701429843</td>
<td width="20%">s@g.com</td>
<td width="10%" align="center"><span class="label label-inverse">DeActive</span>
</td>
</tr>
</tbody>
</table>
<button type="submit" id="deactivebtn" class="btn blue">Deactive</button>
$(document).on('click', '.bradio', function (event) {
var classname = $(this).find('span').attr('class');
if (classname == 'label label-success') {
$('#deactivebtn').text('Deativate');
} else if (classname == 'label label-inverse') {
$('#deactivebtn').text('Deativate');
}
});
这是我的jsfiddle
http://jsfiddle.net/kz2j2jjy/7/
请有人帮帮我。
答案 0 :(得分:2)
您应该更改此行:
var classname = $(this).find('span').attr('class');
为此:
var classname = $(this).closest('tr').find('span').attr('class');
基本上首先转到共同父节点,然后找到 span 。