<form action="#" method="POST">
<table class="table beauty-table table-hover">
<thead>
<tr>
<th>Nombre</th>
</tr>
</thead>
<tbody>
<tr>
<td class="beauty-hover">
<input type="text" value="" placeholder="Nombre">
</td>
</tr>
<tr>
<td>
<h4>Crear Campo</h4>
<!--<input class="enviar" type="submit" value="Crear">-->
</td>
</tr>
</tbody>
</table>
<table id="columnas" class="table beauty-table table-hover">
<thead>
<tr>
<th>Nombre</th>
<th>tipo</th>
<th>longitud</th>
<th>predeterminado</th>
<th>indice</th>
<th>null</th>
<th>A_I</th>
</tr>
</thead>
<tbody>
<tr>
<td class="beauty-hover">
<input type="text" value="" placeholder="Nombre">
</td>
<td class="">
<select class="form-control">
<option>Texto</option>
<option>Numerico</option>
<option>Booleano</option>
<option>Porcentaje</option>
<option>$</option>
</select>
</td>
<td class="">
<input type="text" value="" placeholder="Longitud">
</td>
<td class="">
<select class="form-control">
<option>NINGUNO</option>
<option>LLAVE FORANEA</option>
<option>LLAVE PRIMARIA</option>
</select>
</td>
<td class="">
<label>
<div class="checkbox">
<input type="checkbox"></input>
<i class="fa fa-square-o"></i>
</label>
</div>
</td>
<td class="">
<div class="checkbox">
<label>
<input type="checkbox"></input>
<i class="fa fa-square-o"></i>
</label>
</div>
</td>
<td class="">
<div class="checkbox">
<label>
<input type="checkbox"></input>
<i class="fa fa-square-o"></i>
</label>
</div>
</td>
</tr>
<tr id="crear">
<td></td>
<td></td>
<td>
<button id="crearb" class="enviar" type="button" value="Crear">Crear</button>
</td>
</tr>
</tbody>
</table>
</form>
答案 0 :(得分:1)
首先想到的是, :eq()
$('form table:eq(1) tr:eq(0)')
$('form table:eq(1) tr:eq(0)').css('background', 'green');
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<form action="#" method="POST">
<table class="table beauty-table table-hover">
<thead>
<tr>
<th>Nombre</th>
</tr>
</thead>
<tbody>
<tr>
<td class="beauty-hover"><input type="text" value="" placeholder="Nombre"></td>
</tr>
<tr>
<td><h4>Crear Campo</h4><!--<input class="enviar" type="submit" value="Crear">--></td>
</tr>
</tbody>
</table>
<table id="columnas" class="table beauty-table table-hover">
<thead>
<tr>
<th>Nombre</th>
<th>tipo</th>
<th>longitud</th>
<th>predeterminado</th>
<th>indice</th>
<th>null</th>
<th>A_I</th>
</tr>
</thead>
<tbody>
<tr>
<td class="beauty-hover"><input type="text" value="" placeholder="Nombre"></td>
<td class=""><select class="form-control">
<option>Texto</option>
<option>Numerico</option>
<option>Booleano</option>
<option>Porcentaje</option>
<option>$</option>
</select></td>
<td class=""><input type="text" value="" placeholder="Longitud"></td>
<td class=""><select class="form-control">
<option>NINGUNO</option>
<option>LLAVE FORANEA</option>
<option>LLAVE PRIMARIA</option>
</select></td>
<td class=""> <label> <div class="checkbox">
<input type="checkbox"/>
</div></label>
</td>
<td class=""><div class="checkbox">
<input type="checkbox"></input>
<i class="fa fa-square-o"></i>
</div>
</td>
<td class=""><div class="checkbox">
<label>
<input type="checkbox"></input>
<i class="fa fa-square-o"></i>
</div> </label>
</td>
</tr>
</table>
</form>
&#13;
下一个是 :not()
$('form table:not(:first) tr:first')
$('form table:not(:first) tr:first').css('background', 'green');
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<form action="#" method="POST">
<table class="table beauty-table table-hover">
<thead>
<tr>
<th>Nombre</th>
</tr>
</thead>
<tbody>
<tr>
<td class="beauty-hover"><input type="text" value="" placeholder="Nombre"></td>
</tr>
<tr>
<td><h4>Crear Campo</h4><!--<input class="enviar" type="submit" value="Crear">--></td>
</tr>
</tbody>
</table>
<table id="columnas" class="table beauty-table table-hover">
<thead>
<tr>
<th>Nombre</th>
<th>tipo</th>
<th>longitud</th>
<th>predeterminado</th>
<th>indice</th>
<th>null</th>
<th>A_I</th>
</tr>
</thead>
<tbody>
<tr>
<td class="beauty-hover"><input type="text" value="" placeholder="Nombre"></td>
<td class=""><select class="form-control">
<option>Texto</option>
<option>Numerico</option>
<option>Booleano</option>
<option>Porcentaje</option>
<option>$</option>
</select></td>
<td class=""><input type="text" value="" placeholder="Longitud"></td>
<td class=""><select class="form-control">
<option>NINGUNO</option>
<option>LLAVE FORANEA</option>
<option>LLAVE PRIMARIA</option>
</select></td>
<td class=""> <label> <div class="checkbox">
<input type="checkbox"/>
</div></label>
</td>
<td class=""><div class="checkbox">
<input type="checkbox"></input>
<i class="fa fa-square-o"></i>
</div>
</td>
<td class=""><div class="checkbox">
<label>
<input type="checkbox"></input>
<i class="fa fa-square-o"></i>
</div> </label>
</td>
</tr>
</table>
</form>
&#13;
最后, :last (因为你只有两张桌子,所以有效)
$('form table:last tr:first')
$('form table:last tr:first').css('background', 'green');
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<form action="#" method="POST">
<table class="table beauty-table table-hover">
<thead>
<tr>
<th>Nombre</th>
</tr>
</thead>
<tbody>
<tr>
<td class="beauty-hover"><input type="text" value="" placeholder="Nombre"></td>
</tr>
<tr>
<td><h4>Crear Campo</h4><!--<input class="enviar" type="submit" value="Crear">--></td>
</tr>
</tbody>
</table>
<table id="columnas" class="table beauty-table table-hover">
<thead>
<tr>
<th>Nombre</th>
<th>tipo</th>
<th>longitud</th>
<th>predeterminado</th>
<th>indice</th>
<th>null</th>
<th>A_I</th>
</tr>
</thead>
<tbody>
<tr>
<td class="beauty-hover"><input type="text" value="" placeholder="Nombre"></td>
<td class=""><select class="form-control">
<option>Texto</option>
<option>Numerico</option>
<option>Booleano</option>
<option>Porcentaje</option>
<option>$</option>
</select></td>
<td class=""><input type="text" value="" placeholder="Longitud"></td>
<td class=""><select class="form-control">
<option>NINGUNO</option>
<option>LLAVE FORANEA</option>
<option>LLAVE PRIMARIA</option>
</select></td>
<td class=""> <label> <div class="checkbox">
<input type="checkbox"/>
</div></label>
</td>
<td class=""><div class="checkbox">
<input type="checkbox"></input>
<i class="fa fa-square-o"></i>
</div>
</td>
<td class=""><div class="checkbox">
<label>
<input type="checkbox"></input>
<i class="fa fa-square-o"></i>
</div> </label>
</td>
</tr>
</table>
</form>
&#13;
答案 1 :(得分:1)
你会使用:
var tr = $('form table:eq(1) tr').first(); //OR
var tr = $('form table:eq(1) tr:eq(0)'); //OR
var tr = $('form').find('table').eq(1).find('tr').first();
答案 2 :(得分:1)
您可以使用各种选择器进行以下操作。
根据你的html,你有第二个表id
,你可以使用id
选择器来定位最简单和最快的第二个表。
$('#columnas tbody tr:first');
接下来,您可以使用:eq()选择器将匹配元素集合减少到指定索引处的元素。
$('form table:eq(1) tbody tr:first')
接下来,你可以使用:nth-child()选择器选择所有父元素的nth-child元素,根据你的html选择第二个表格。
$('form table:nth-child(2) tbody tr:first')
注意:tr:first
会选择第一个tr
。