I have a table structure like this..
<form name="kuchbhi">
<table id="x">
<tr name="alpha">
<td><input name="a" type="checkbox"></td>
<td><input name="b" type="checkbox"></td>
</tr>
<tr name="beta">
<td><input name="a" type="checkbox"></td>
<td><input name="b" type="checkbox"></td>
</tr>
</table>
<table id="y">
<tr name="alpha">
<td><input name="a" type="checkbox"></td>
<td><input name="b" type="checkbox"></td>
</tr>
<tr name="beta">
<td><input name="a" type="checkbox"></td>
<td><input name="b" type="checkbox"></td> <!--This one-->
</tr>
</table>
</form>
Now, I have only 2 info (tr name) and (input name). For example I have (beta, a). Now I want to put a check on that checkbox (on the second table named y). How to select that checkbox?
try this:
var trname = 'beta'; var inname = 'a'; $( 'tr[name="' + trname + '"] input[name="' + inname + '"]' ).attr( 'checked', 'checked' );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form name="kuchbhi"> <table id="x"> <tr name="alpha"> <td><input name="a" type="checkbox"></td> <td><input name="b" type="checkbox"></td> </tr> <tr name="beta"> <td><input name="a" type="checkbox"></td> <td><input name="b" type="checkbox"></td> </tr> </table> <table id="y"> <tr name="alpha"> <td><input name="a" type="checkbox"></td> <td><input name="b" type="checkbox"></td> </tr> <tr name="beta"> <td><input name="a" type="checkbox"></td> <td><input name="b" type="checkbox"></td> <!--This one--> </tr> </table> </form>
使用jquery,如下所示:
$('#y tr[name=beta] td>input[name=b]')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.