jQuery 배열 관리 > script

본문 바로가기

script

jQuery 배열 관리

작성일 12-11-29 18:08

페이지 정보

작성자서방님 조회 145회 댓글 0건

본문

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>

댓글목록

등록된 댓글이 없습니다.

전체 846건 9 페이지
게시물 검색
Copyright © 서방님.kr All rights reserved.
PC 버전으로 보기