2013-03-11 3 views
0

jQuery에서 다음 코드를 수행하는 데 더 짧은 표기법이 있습니까? 모든 단락의 html 콘텐츠를 기록하고 싶습니다.jQuery 문자열에 객체 배열

var array = $('p').get(); 
$.each(array, function(i, val) 
{ 
    console.log(val); 
}); 
+0

어떤 정보가 실제는 HTMLElement를 참조합니다 this' 콘솔 –

답변

0

당신이 문단의 콘텐츠를 하시겠습니까?

console.log($('p').text())

+0

정말 분명하지만 어쨌든 나는 그것을 놓쳤습니다! – faiahime

+0

@faiahime 도움이된다면 기쁩니다. : D 답변을 수락하는 것을 잊지 마십시오. – Ovilia

0

당신은 시도

console.log(array.join('')) 
0

을 시도 할 수 있습니다 당신은 체인 코드 수이

$.each(($('p').get()), function(i, val) 
{ 
    console.log(val); 
}); 
0

:

$('p').each(function(){ 
    console.log($(this).html()); 
}); 
+1

'에 표시 싶어. 'this.html()'이 아니라'this.innerHTML'을 사용해야합니다. –

+1

JQuery의 'this'를 사용하여 내 대답을 편집했습니다. – Bigood

0

당신이 시도 할 수 있습니다 기대 형식의 종류에 따라 :

array.toSTring() 

이로 구분 배열 요소가 발생할 것 ","

0

당신은 할 문자 수

console.log($('p').get()); 
0

시도지도()

var pArray=$('p').map(function() { 
    return this.id; 
}).get(); 
console.log(pArray);