1. 程式人生 > >js向陣列物件中迴圈賦值

js向陣列物件中迴圈賦值

		<script>
			var receive = document.getElementsByClassName('receive');
			console.log($('.receive:eq(0)').find('.td_id').text());

			var data = [];
			for(var i = 0;i<receive.length-1;i++){
				data.push({name:$('.receive:eq('+i+')').find('.td_area').text(),value:$('.receive:eq('+i+')').find('.td_geo').text(),id:$('.receive:eq('+i+')').find('.td_id').text()})
			}
			console.log(data);
		</script>
宣告一個空陣列,在for迴圈中 向此陣列中 push 物件

物件的各屬性值通過從頁面節點中獲取。