我试图连续找到第一个复选框,每次检查表中的第一个复选框时,这里是表格和docready中的代码
$('.otherMoneyToo').blur(function() {
thisSelector = $('tr td:first-child input').attr('name');
if ($(this).val() == '') {
$("input[name='" + thisSelector + "']").prop('checked', false);
} else {
var myTransAmount = $(this).val();
$('.otherMoney').prop('checked', false);
$('.otherMoneyToo').val('');
$(this).val(myTransAmount);
$("input[name='" + thisSelector + "']").prop('checked', true);
}
});
HTML:
<table class='drkblue moneyTransfer' align='center'>
<tr class='main'>
<td colspan='4'>
<hr>Transfer money:</td>
</tr>
<tr class='main'>
<td>
<input type='checkbox' class='otherMoney' name='omcb00000006040000'>0000000604:SAVINGS/SHARE ACCT</td>
<td>2,161.50</td>
<td>Amount: </td>
<td>
<input name='omTrans00000006040000' class='money otherMoneyToo'>
</td>
</tr>
<tr class='main'>
<td>
<input type='checkbox' class='otherMoney' name='omcb00000006040090'>0000000604:CHECKING/DRAFT ACCT</td>
<td>677.03</td>
<td>Amount: </td>
<td>
<input name='omTrans00000006040090' class='money otherMoneyToo'>
</td>
</tr>
</table>
答案 0 :(得分:1)
你可能没有保持模糊的背景。您希望将更改保留在模糊发生的行中。因此,
thisSelector=$('tr td:first-child input').attr('name');
应该是:
var thisSelector = $(this).closest('tr').find('input').attr('name');
$('.otherMoneyToo').blur(function(){
thisSelector= $(this).closest('tr').find('input').attr('name');
if ($(this).val()=='') {
$("input[name='"+thisSelector+"']").prop('checked',false);
} else {
var myTransAmount=$(this).val();
$('.otherMoney').prop('checked',false);
$('.otherMoneyToo').val('');
$(this).val(myTransAmount);
$("input[name='"+thisSelector+"']").prop('checked',true);
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class='drkblue moneyTransfer' align='center' >
<tr class='main'><td colspan='4'><hr>Transfer money:</td></tr>
<tr class='main'>
<td><input type='checkbox' class='otherMoney'
name='omcb00000006040000' >0000000604:SAVINGS/SHARE ACCT</td>
<td>2,161.50</td>
<td>Amount: </td>
<td><input name='omTrans00000006040000' class='money otherMoneyToo'></td>
</tr>
<tr class='main'>
<td><input type='checkbox' class='otherMoney'
name='omcb00000006040090' >0000000604:CHECKING/DRAFT ACCT</td>
<td>677.03</td>
<td>Amount: </td>
<td><input name='omTrans00000006040090' class='money otherMoneyToo'></td>
</tr>
</table>
&#13;