SPATIUM Mobile
주소복사
About Operating System Languages Tools Favorites Notice Visit TEST  
     ADK (3)
     android (3)
     ASP (5)
     ASP.Net (1)
     C# (5)
     HTML (9)
     JAVA (7)
     JavaScript (9)
     jQuery (5)
     Mobile Web (2)
     node.js (1)
     Oracle (8)
     PHP (7)
     Spring Framework (4)
     SQL (17)
     WPF (5)
   ID  
   Password  
  |  
  Location United States
  IP Address 3.149.255.162
2024. 04
123456
78910111213
14151617181920
212223
24
252627
282930
Category  Languages, jQuery
Writer 김태우 Date 2012-05-07 11:20:37 Visit 15162
jquery 배열 제어, each 메서드 이용

 

jquery each 메서드 이용


- 형태

    $(selector).each(function(index, item){} );

    $.each(object, function(index, item){} );

 - 배열 또는 배열처럼 사용 가능한 같은 id 또는 class 복수개의 item을 조작할때 사용

 

사용 경우 1) 동일 클래스 명을 가진 div 객체를 순차적으로 출력할때( 하기 소스는 << 이전 버튼 클릭시 )

 

$('.view_items').each(function (index, item) {    // 클래스 view_items 의 index 및 객체 item

    if( $(item).css('display') == 'block' ){    // 현재 출력되고 있는 item 채크

        $('.view_items').css('display', 'none');

        if( index == 0){

            $('.view_items').last().css('display', 'block');   
// index 가 0이면, 마지막 객체를 출력

        }else{

            $('.view_items').eq(index-1).css('display', 'block');   
// 현재 출력된 item의 바로 이전것 출력
                                    // eq() : 특정 위치에 있는 문서 객체 선택, first()는 첫번째, last()는 마지막
        }
    
        return false;   
// each 문을 빠져나감(break) 
  
    }

});

 

 

 

Tags  jquery each 메서드, eq, first, last
  Relation Articles
[Languages-jQuery] jquery 배열 제어, each 메서드 이용 (2012-05-07 11:20:37)
  Your Opinion
Member ID
150 letters
Copyright (C) SPATIUM. All rights reserved.
[SPATIUM]WebMaster Mail