我想通过 jquery 获取除最后一个类 .tr
中的最后一个输入之外的所有输入值,但它对我不起作用,如何修复它?
我尝试:
演示: http://jsfiddle.net/d4xZK/
HTML:
<div class="tr">
<input type="text" value="111">
</div>
<div class="tr">
<input type="text" value="222">
</div>
<div class="tr">
<input type="text" value="333">
</div>
<div class="tr">
<input type="text" value="444">
</div>
jQuery:
$('.tr').each(function(){
var mpiVal = $('.tr input').not(':last').val();
alert(mpiVal)
)}
最佳答案
您可以 slice()
关闭最后一个:
$('.tr').slice(0, -1).each(function() {
var mpiVal = $('input', this).val();
console.log(mpiVal);
});
关于javascript - 通过jquery获取除最后一个之外的输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14706446/