我怎樣才能使數組中的這個簡單?:jQuery和串聯多個域值
var address = jQuery.trim($("#Address1").val()) + " " + jQuery.trim($("#City").val()) + " " + jQuery.trim($("#State").val()) + " " + jQuery.trim($("#Zip").val());
我怎樣才能使數組中的這個簡單?:jQuery和串聯多個域值
var address = jQuery.trim($("#Address1").val()) + " " + jQuery.trim($("#City").val()) + " " + jQuery.trim($("#State").val()) + " " + jQuery.trim($("#Zip").val());
試試這個:
var address = "";
$("#Address1, #City, #State, #Zip").each(function(){
address += $.trim($(this).val()) + " ";
});
如果你正在尋找表格文本輸入,那麼你可以使它更簡單,如下所示:
var address = "";
$(":text").each(function(){
address += $.trim($(this).val()) + " ";
});
堆棧項目和循環:
var arr = ['Address1', 'City', 'State', 'Zip'];
for(var i=0;i<arr.length;i++){
arr[i] = $('#'+arr[i]).val();
}
var address = arr.join(' ');
感謝您的快速回復 – 2011-04-05 17:24:25
感謝您的快速回復 – 2011-04-05 17:24:52