我的表格如下。通过使用visible()
,如何在两个不同的div(hidden_source1和hidden_source2)上选择第一个可见tr
的单选按钮?我已经这样做了,首先是tr
是否可见并且是否在两个div中检查,第二,如果找到可见的tr
,则单击该div中的无线电。
<HTML>
<title></title>
<head>
<script type="text/JavaScript">
<tab>$(document).ready(function(){
<tab>$("#hidden_source1").find( "input", ".rower:visible" )[0].checked = true;
<tab>$("#hidden_source1").find( "input", ".rower:visible" )[0].click
});
<tab>$(document).ready(function(){
<tab>$("#hidden_source2").find( "input", ".rower:visible" )[0].checked = true;
<tab>$("#hidden_source2").find( "input", ".rower:visible" )[0].click
});
</script>
</head>
<body>
<div id="hidden_source1">
<table id="return_me" class="tbl2" cellspacing="0" cellpadding="0" border="0" width="100%">
<tbody>
<tr class="rower" style="display: none;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
<tr class="rower" style="display: none;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
<tr class="rower" style="display: none;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
<tr class="rower" style="display: table-row;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
<tr class="rower" style="display: table-row;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
<tr class="rower" style="display: table-row;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
</tbody>
</table>
</div>
<div id="hidden_source2">
<table id="return_me" class="tbl2" cellspacing="0" cellpadding="0" border="0" width="100%">
<tbody>
<tr class="rower" style="display: none;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
<tr class="rower" style="display: none;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
<tr class="rower" style="display: none;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
<tr class="rower" style="display: table-row;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
<tr class="rower" style="display: table-row;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
<tr class="rower" style="display: table-row;">
<td width="4"> </td>
<td width="30">
<input class="return_r" type="radio" name="return">
</td>
</tr>
</tbody>
</table>
</div>
</body>
</HTML>
答案 0 :(得分:3)
$(document).ready(function(){
$( 'div[id^="hidden_source"]' ).each(
function(){
$( ".rower:visible:first input", this ).prop( "checked", true );
}
);
});
您需要为hidden_source1和hidden_source2 ...
中的无线电输入设置不同的名称答案 1 :(得分:3)
您也可以使用
$(function(){
$('tr.rower:visible:first input').attr('checked', true);
});
答案 2 :(得分:0)
$(document).ready(function(){
$( 'div[id^="hidden_source"]' ).each(
function(){
$( ".rower:visible:first input", this ).prop( "checked", true );
}
);
});
(OR)
BY THE REFERENCE OF Mr.methodin'S ANSWER
$(document).ready(function(){
$('.tbl1').find('tr.rower:visible:first input').attr('checked', true);
$('.tbl2').find('tr.rower:visible:first input').attr('checked', true);
});