2011-08-31 3 views
1
변수

에서 클릭 된 요소 저장소의 폭을 얻을 나는 몇 가지 기본적인 마크 업을 가지고있다. 다음 jQuery 코드가 있습니다 :jQuery를이

var listWidth = []; 
    $('.content').click(function(){ 
     listWidth.push($(this).width()); 
    }); 

    console.log(listWidth); 

너비 값을 배열로 전달하지 않습니다. 다음과 같이 알림을 사용할 때 작동합니다.

var listWidth = []; 
    $('.content').click(function(){ 
     alert($(this).width()); 
    }); 

    console.log(listWidth); 

나를 도와 줄 수있는 사람이 있습니까? 미리 감사드립니다.

+1

클릭 기능이 트리거되기 전에 배열을 로그합니다 – rsplak

답변

4

클릭 이벤트 내에서 console.log으로 전화하십시오.

var listWidth = []; 
$('.content').click(function(){ 
    listWidth.push($(this).width()); 
    console.log(listWidth); 
}); 

배열이 비어있을 때 로깅 중이므로 click 이벤트가 배열에 아무것도 넣지 않습니다.