jQuery 배열 관리 > script

본문 바로가기
사이트 내 전체검색

script

jQuery 배열 관리

페이지 정보

작성자 서방님 댓글 0건 조회 218회 작성일 12-11-29 18:08

본문

JQuery에서는 each()메서를 통해서 배열을 관리한다.

JavaScript에서 for in 반복문과 비슷하게 사용된다.

- each() 메서드의 두가지 사용 형태

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

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


-sample code-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>

<script>

$(document).ready(function(){

var array=[{name: 'Hanbit Media', link: 'http://hanb.co.kr'},

{name: 'Naver', link: 'http://naver.com'},

{name: 'Daum', link: 'http://daum.net'},

{name: 'Paran', link: 'http://paran.com'},

];

//$.each() 메서드를 사용

$.each(array, function (index, item){

var output = '';


output += '<a href=' + item.link+">';

output += '     <h1>' + item.name + '</h1>';

output += '</a>';


document.body.innerHTML +=output;

});

});

</script>

</head>


<body>

</body>

</html>

댓글목록

등록된 댓글이 없습니다.

Total 846건 9 페이지
게시물 검색

회원로그인

접속자집계

오늘
81
어제
190
최대
1,347
전체
167,489
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.