jQuery | javascript | CSS

24.jQuery - 속성값 복사 ( 02.Selectors - 02.Text )

Godffs 2009. 11. 9. 11:20
반응형
input 태그의 모든 text타입들을 전부 타겟으로 선택할때 사용합니다.
            $(':text').메서드()
이런형식으로 쓰시면 모든 input type="text" 형식의 태그들이 타겟으로 설정됩니다.
02.Text.htm

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

<head>

    <title>Text 박스의 복사</title>

    <style type="text/css">

        .silver { background-color:Green; }

    </style>

 

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

    <script type="text/javascript">

        $(document).ready(function() {

            // 모든 텍스트박스의 배경을 Silver 설정

            $(':text').addClass("silver");

            // 첫번째 텍스트박스의 값을 두번째 텍스트박스로 복사

            $('#btnCopy').click(function() {

                $('#txtID').val($('#txtUserID:text').val());

            });

        });

    </script>

</head>

<body>

 

    아이디 : <input type="text" id="txtUserID" /><hr />

    <input type="button" id="btnCopy" value="복사" /><hr />

    아이디 : <input type="text" id="txtID" />

 

</body>

</html>


결과화면

[그림24-1]



반응형