Javascript 访问选择选项并仅在第一行输入文本
我想操纵一个选择选项并在表格上输入文本区域。代码如下所示:Javascript 访问选择选项并仅在第一行输入文本,javascript,jquery,Javascript,Jquery,我想操纵一个选择选项并在表格上输入文本区域。代码如下所示: <table id="list2" class="table table-bordered> <thead> <tr> <th style="width:15%">Item</th> <th style="width:22.5%">Remarks</th> <th styl
<table id="list2" class="table table-bordered>
<thead>
<tr>
<th style="width:15%">Item</th>
<th style="width:22.5%">Remarks</th>
<th style="width:10%">Manhour</th>
<th>Act</th>
</tr>
</thead>
<tbody>
<tr class="list2_var">
<td>
<select class="form-control cleaning-item" name="list2_cleaning_item_0" id="list2_cleaning_item_0">
<option disabled="" selected="">Pilih</option>
<option value="01">Certificate</option>
<option value="02">Interior</option>
<option value="03">Exterior</option>
<option value="04">Foreign Marking</option>
</select>
</td>
<td>
<input class="form-control remarks" name="list_2_remarks_0" placeholder="Remarks" id="list_2_remarks_0" type="text">
</td>
<td>
<input class="form-control" name="list_2_manhour_0" placeholder="Manhour" type="text">
</td>
<td class="del_area04">
<button style="display: none;" class="list2_del btn btn-block btn-danger" type="button"><i class="fa fa-trash-o"></i></button>
</td>
</tr>
</tbody>
$('#list2 td .remarks').val('example');
$('#list2 td .cleaning-item').val('02');
但它会操纵所有的争吵。我怎样才能使它只在第一行,然后,他们两个将被禁用只是在第一行??
非常感谢任何帮助。使用
:first
选择器或.first()
jquery
tr:first
或
有多种方法可以选择第一行 使用:eq() 或者使用.eq() 或使用:首先 或者使用 什么是第一(0)?看起来像是
eq(0)
@charlietfl中的复制/粘贴错误,它是first()
:)
$('tr').first()
$('#list2 tbody tr:eq(0) td .remarks').val('example');
$('#list2 td tr:eq(0) .cleaning-item').val('02');
$('#list2 tbody tr').eq(0).find('td .remarks').val('example');
$('#list2 td tr').eq(0).find('.cleaning-item').val('02');
$('#list2 tbody tr:first td .remarks').val('example');
$('#list2 td tr:first .cleaning-item').val('02');
$('#list2 tbody tr').first().find('td .remarks').val('example');
$('#list2 td tr').first().find('.cleaning-item').val('02');