[Slice.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>slice() 메서드로 지정된 개체만 가져오기</title>

    <style type="text/css">

        .red { color:Red; }

    </style>

    <script src="js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(document).ready(function() {

            // size() 해당 결과값(집합)의 개수

            alert("현재 웹 페이지에는 " + $('input').size() + "개의 input 태그가 있다.");

 

            // 2번째와 3번째만 스타일 적용

            $('input').slice(1, 3).addClass('red'); // 1번째 인덱스에서 (3-1)번째 인덱스까지

        });   

    </script>

</head>

<body>

 

<h1>2번째와 3번째 버튼에만 빨간 글씨 적용</h1>

 

<input type="button" value="버튼" />

<input type="button" value="버튼" />

<input type="button" value="버튼" />

<input type="button" value="버튼" />

 

</body>

</html>

 

 


-------------------------------------------------------------------------------------




[실행결과]





--> 위의 그림의 '메시지 박스'에 있는 '확인'버튼 클릭 후 화면.




Posted by holland14
: