【发布时间】:2018-11-27 16:56:45
【问题描述】:
我需要选择最后一个没有readonly 属性的输入。
我尝试过input:last:not([readonly]) 和input:not([readonly]):last,但似乎不起作用。
有什么想法吗?
编辑:
正如您向您报告的那样,它可以在您的 JS Fiddle 上进行测试,代码如下 (JS Fiddle here):
当您在表格中的输入上按Enter键时,应该将焦点设置在下一个输入上,但是当它是最后一个非只读输入时,我需要将焦点设置在带有Barcode标签的输入上.
HTML
Barcode: <input name="barcode" type="text" id="formInput_91" class="form-control" value="" autocomplete="off">
<br>
<table id="table_invoiceProducts" class="table">
<thead>
<tr>
<th>Article</th>
<th>Descriptio</th>
<th>Price</th>
<th>Tax</th>
<th>Qty</th>
<th>Subtotal</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" style="border: none; width: 32px;" name="product[1543338984947183200][productId]" class="adjustInputWidth input_productId" value="456" readonly=""></td>
<td><input type="text" style="border: none; width: 40px;" name="product[1543338984947183200][description]" class="adjustInputWidth input_description" value="Test"></td>
<td><input type="number" style="border: none; width: 58px;" name="product[1543338984947183200][price]" class="adjustInputWidth input_priceUnit" data-id="1543338984947183200" value="25.00" min="0" step="0.01"></td>
<td><input type="number" class="adjustInputWidth input_tax" style="border: none; width: 50px;" data-id="1543338984947183200" value="0.00" name="product[1543338984947183200][tax]"></td>
<td><input type="number" value="1" min="1" style="border: none; width: 26px;" data-id="1543338984947183200" class="input_quantity adjustInputWidth" name="product[1543338984947183200][quantity]"></td>
<td><span style="color:#000;" class="span_priceSubTotal" data-id="1543338984947183200">25.00</span></td>
<td><span style="color:#000;" data-id="1543338984947183200" class="span_priceTotal">25.00</span></td>
</tr>
<tr>
<td><input type="text" style="border: none; width: 40px;" name="product[1543338991430875154][productId]" class="adjustInputWidth input_productId" value="1234" readonly=""></td>
<td><input type="text" style="border: none; width: 104px;" name="product[1543338991430875154][description]" class="adjustInputWidth input_description" value="Product"></td>
<td><input type="number" style="border: none; width: 58px;" name="product[1543338991430875154][price]" class="adjustInputWidth input_priceUnit" data-id="1543338991430875154" value="50.00" min="0" step="0.01"></td>
<td><input type="number" class="adjustInputWidth input_tax" style="border: none; width: 50px;" data-id="1543338991430875154" value="0.00" name="product[1543338991430875154][tax]"></td>
<td><input type="number" value="1" min="1" style="border: none; width: 26px;" data-id="1543338991430875154" class="input_quantity adjustInputWidth" name="product[1543338991430875154][quantity]" readonly=""></td>
<td><span style="color:#000;" class="span_priceSubTotal" data-id="1543338991430875154">50.00</span></td>
<td><span style="color:#000;" data-id="1543338991430875154" class="span_priceTotal">50.00</span></td>
</tr>
</tbody>
</table>
JS
$( document ).ready(function() {
$('#table_invoiceProducts').on('keydown', 'input:not(:last)', function(e){
var keyCode = e.keyCode || e.which;
if(keyCode == 9 || keyCode == 13){
e.preventDefault();
$('#table_invoiceProducts input:not([readonly])')[$('#table_invoiceProducts input:not([readonly])').index(this)+1].focus();
$('#table_invoiceProducts input:not([readonly])')[$('#table_invoiceProducts input:not([readonly])').index(this)+1].select();
}
});
$('#table_invoiceProducts').on('keydown', 'input:not([readonly]):last', function(e){
var keyCode = e.keyCode || e.which;
if(keyCode == 9 || keyCode == 13){
e.preventDefault();
$( '#formInput_91' ).focus();
}
});
});
【问题讨论】:
-
您的选择器工作正常:jsfiddle.net/RoryMcCrossan/v72dgx4c。如果您遇到特定问题,那么我们需要查看所有相关代码以重现它
-
@RoryMcCrossan Wou... 我将努力发布完整代码
-
如@RoryMcCrossan所说,用相关的JS代码编辑帖子,看看有没有错别字
-
@RoryMcCrossan 已编辑。