jQuery Core 명령어 - Each()메서드로 반복 탐색 (요소만큼 반복해서 속성 설정 및 가져오기)
.NET프로그래밍/jQuery 1.3.2 2009. 11. 9. 09:51 |[Each.htm]
<!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>
<title>요소만큼 반복해서 속성 설정 및 가져오기</title>
<script src="../js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
//[1] each 메서드 설명
//$('p').each(function (index) { alert(index); });
//[2] for문처럼 반복한다. index는 0부터 자동 증가됨
$('p').each(function (index) {
$(this).attr({ // attr({어트리뷰트:값});
'id': "para-" + index
});
});
//[3] 0번째 요소의 텍스트 읽어오기
$('#btn').click(function () {
alert($('#para-0').text()); // 태그내의 텍스트 읽어오기(text() : 태그안의 값 : C#)
});
});
</script>
</head>
<body>
<p>C#</p>
<p>ASP.NET</p>
<p>Silverlight</p>
<input type="button" id="btn" value="동적으로 생성된 id로 개체 접근" />
</body>
</html>
-------------------------------------------------------------------------------------
[실행결과]
--> 첫 화면.
--> 위의 그림에서 '동적으로 생성된 id로 개체 접근'버튼을 누른 후의 화면.
'.NET프로그래밍 > jQuery 1.3.2' 카테고리의 다른 글
Form관련 jQuery 선택기 명령어 - :input (모든 폼 요소 읽어오기) (0) | 2009.11.09 |
---|---|
jQuery인덱서(Indexer)를 사용하여 HTML 요소 가져오기 (0) | 2009.11.09 |
콜백(CallBack) : 매개변수로 함수를 전달 (0) | 2009.11.09 |
브라우저 버전 나타내기 (0) | 2009.11.09 |
css()메서드를 사용하여 폰트 늘리기 및 줄이기 (0) | 2009.11.09 |