메뉴 건너뛰기

조회 수 276 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

javascript for문 사용 예

//예문1) 미지원 브라우저 없음
for (var i=0; i<array.length; i++) {
    console.log(array[i]);
}

//예문2.1) ie8 이하 미지원
for (var i in array) {
    console.log(array[i]);
}

//예문2.2) object형 변수의 루프 돌리기
var viewModel = {
    entity : undefined,
    longitude: 127.33887522,
    latitude: 36.34803794,
    height: 0,
    heading: 0,
    pitch: 0,
    roll: 0
};
for (var name in viewModel) {
    console.log(name + ": " + viewModel[name]);
}

//예문3.1) ie9, ff1.5 미만 미지원
array.forEach(function(currentValue, index, arr), thisValue);

//예문3.2) ie9, ff1.5 미만 미지원
var numbers = [65, 44, 12, 4];
function myFunction(item, index, arr) {}
numbers.forEach(myFunction);

 

jQuery 루프문 사용 예

//예문1)
$("li").each(function(index) {
    console.log(index + ": " + $(this).text());
});

//예문2)
$("div").each(function(index, element) {
    //$(element) == $(this)
    $(element).css("color", "yellow");
    if ($(this).is("#stop")) {
        $("span").text("index : " + index);

        //continue : return true;
        //break : return false;
        return false;
    }
});

//예문3)
var result = {
    navigationList : {
        "0": {
            "coordinatex" : "126",
            "coordinatey" : "36",
        },
        "1": {
            "coordinatex" : "126",
            "coordinatey" : "36",
        }
    }
};
$.each(result.navigationList, function(idx, data) {
    console.log('for:',data.coordinatex, data.coordinatey);
});

//예문4)
var obj = {
    "a": "1",
    "b": "2"
};
$.each(obj, function(key, value) {
    alert(key + ": " + value);
});

//예문5)
$.each([52, 97], function(index, value) {
    alert(index + ": " + value);
});

  1. JS 첵박스 샘플

    Date2019.06.04 Views694
    Read More
  2. 모달 띄우는 코드

    Date2021.03.25 Views657
    Read More
  3. jQuery - checkbox 전체 선택, 해제 기능 및 단일 체크박스가 해제되었을때 전체 선택 해제 하기

    Date2021.03.09 Views613
    Read More
  4. 간단한 마우스 포인터 따라 다니기

    Date2021.03.26 Views594
    Read More
  5. jQuery - ajax xhr을 활용한 파일 업로드 진행 상태 확인하기

    Date2021.03.09 Views586
    Read More
  6. jQuery - 클릭이벤트 동적 처리하기($("").click(), on('click') 차이)

    Date2021.03.09 Views580
    Read More
  7. SELECTBOX MULTIPLE 검색하기

    Date2021.03.26 Views568
    Read More
  8. jQuery - radio, checkBox값 가져오기, 선택하기, 제어 등

    Date2021.03.09 Views543
    Read More
  9. ajax 동기화 처리하기

    Date2021.03.25 Views416
    Read More
  10. Cesium에서 canvas 화면 center 지점의 좌표 취득

    Date2021.03.25 Views370
    Read More
  11. jQuery - 드래그, 리사이즈 이벤트에 따른 영역 침범 막기

    Date2021.03.09 Views363
    Read More
  12. 목록의 체크 선택/해제에 따라 [전체선택] 체크박스를 체크하거나 해제하기

    Date2021.03.25 Views329
    Read More
  13. 최초 접속시 css와 script가 로딩되지 않을때

    Date2021.03.25 Views322
    Read More
  14. 다중 select

    Date2021.03.31 Views316
    Read More
  15. click에 따른 마우스 휠 on off

    Date2021.03.31 Views303
    Read More
  16. jQuery - 드래그앤드롭(DragAndDrop)을 통한 파일 업로드

    Date2021.03.09 Views291
    Read More
  17. fadeIn() , fadeOut() 을 이용한 간단한 자동 그림 전환

    Date2021.03.26 Views285
    Read More
  18. 항상 최신버전으로 사용하기

    Date2021.03.26 Views284
    Read More
  19. 기본 동작 막기

    Date2021.03.25 Views284
    Read More
  20. javascript, jQuery에서 루프 돌리기 예 (for, forEach, each)

    Date2021.03.25 Views276
    Read More
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 Next
/ 9

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved