[英]Get input value except the last by jquery
我想通過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)
)}
$('.tr').not(':last').each(function(){
var mpiVal = $(this).children('input').val();
alert(mpiVal)
});
或者,您可以簡單地使用正確的選擇器;
$('.tr:not(:last) input').each(function(){
var mpiVal = $(this).val();
alert(mpiVal);
});
最后一行有語法錯誤
var arr = []
$('.tr:not(:last)').each(function(){
arr.push.call(arr,$(this).find('input').first().val());
});
alert(arr);
$(".tr:not(:last) input").map(function(){ return $(this).val() }).get()
返回["111", "222", "333"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.