① JQuery 소스

<?xml version="1.0" encoding="EUC-KR" ?>

<!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=EUC-KR" />

<title>JQuery 3(동적 생성과 traversing)</title>

        <link type="text/css" href="css/custom-theme/jquery-ui-1.8.23.custom.css" rel="stylesheet" />

        <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>

        <script type="text/javascript" src="js/jquery-ui-1.8.23.custom.min.js"></script>

        <script type="text/javascript">

        // $ >> jQuery 객체

        // 버튼을 찾아서 click이벤트를 걸고 클릭시 alert("클릭"); 되도록

        $(function(){

               $(":button[value=실행]").click(function(){

                       // 모든 div 이미지를 추가

                       $("div").append("<img src='teayeon2.jpg' width='50'/>")

                              .find(':odd').width(100).click(function(){

                                      $(this).toggle(2000);

                              }).end().animate({height:"+=20", width:"-=100"},1000);

                       // end(): 끝내고 처음 선택자로 돌아간다.

                       // json 방식 : {name:value, name1:value1}

               });

               var no=1;

               $("div.target").dblclick(function(){

                       $(this).prepend(no++);

               });

               $("div").css("border","solid thin blue")

                       .css("background-color", "#D0D0D0"); // background-color = backgroundColor

        });

        </script>

</head>

<body>

        <input type="button" value="실행" />

        <div class="target">디아이브이1</div>

        <div class="target">디아이브이2</div>

        <div class="target">디아이브이3</div>

        <div class="target">디아이브이4</div>

        <div class="target">디아이브이5</div>

</body>

</html>


② 실행화면

JQuery 3(동적 생성과 traversing)

디아이브이1
디아이브이2
디아이브이3
디아이브이4
디아이브이5


블로그 이미지

모데스티

,

① JQuery소스

<?xml version="1.0" encoding="EUC-KR" ?>

<!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=EUC-KR" />

<title>Insert title here</title>

        <link type="text/css" href="css/custom-theme/jquery-ui-1.8.23.custom.css" rel="stylesheet" />

        <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>

        <script type="text/javascript" src="js/jquery-ui-1.8.23.custom.min.js"></script>

        <script type="text/javascript">

               $(function(){

                       // body 로딩이 끝나고 실행된다.

                       // alert("정말??/");

                       $("#all").click(function(){

                              // this>> all function안에 다시 all 써야하는 경우 대체할 있다.

                              // if($(this).attr("checked")=="checked")

                              var boo = false;

                              if($(this).is(":checked")){

                                      // $("input[name=cb]").attr("checked","checked");

                                      //$("input[name=cb]").attr("checked",false);

                                      boo = true;

                              } $("input[name=cb]").attr("checked",boo);

                       });

               });

               // Jquery 사용하지 않고 구현하기

               function chk(all){

                       var cb = document.getElementsByName("cb"); // 배열

                       var boo = false;

                       if(all.checked) boo = true;

                       for(var i=0; i<cb.length; i++){

                              cb[i].checked=boo;

                       }

                      

               }

        </script>

</head>

<body>

        <input type="checkbox" value="all" id="all" checked="checked" onclick="chk(this);"/> 전체  <br />

        <input type="checkbox" value="1" name="cb"/> 1  <br />

        <input type="checkbox" value="2" name="cb"/> 2  <br />

        <input type="checkbox" value="3" name="cb"/> 3  <br />

        <input type="checkbox" value="4" name="cb"/> 4  <br />

        <input type="checkbox" value="5" name="cb"/> 5  <br />

        <input type="checkbox" value="6" name="cb"/> 6  <br />

        <input type="checkbox" value="7" name="cb"/> 7  <br />

        <input type="checkbox" value="8" name="cb"/> 8  <br />

        <input type="checkbox" value="9" name="cb"/> 9  <br />

        <input type="checkbox" value="10" name="cb"/> 10  <br />

</body>

</html>


② 실행화면

Insert title here 전체
1번
2번
3번
4번
5번
6번
7번
8번
9번
10번


블로그 이미지

모데스티

,

① JQuery 소스

<?xml version="1.0" encoding="EUC-KR" ?>

<!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=EUC-KR" />

<title>JQuery 1</title>

        <link type="text/css" href="css/custom-theme/jquery-ui-1.8.23.custom.css" rel="stylesheet" />

        <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>

        <script type="text/javascript" src="js/jquery-ui-1.8.23.custom.min.js"></script>

        <script type="text/javascript">

               function execute() {

                       // Jquery에서는 메소드이름이 $

                       // $("#target").toggle(3000); // id target선택 ,hide() 숨기기, toggle() = hide()+show()

                       // $("img.ttt").toggle(1000); // img태그중 class ttt 선택

                       // $("img:first").fadeOut(1000); // img태그중 첫번째

                       // $("img:last").fadeOut(1000); // img태그중 마지막 , 이펙트와 관련된 것들은 동시실행

                       // $("img:even").toggle(1000); // img 홀수번째를 toggle : index 0부터 시작(0 짝수)

                       // $("div img").attr("src","teayeon.jpg"); // div img태그에 있는 사진 바꾸기, 속성세팅

                       // document.getElementById("horse").src="teayeon.jpg";

                       // alert($("div img").attr("src")); // 속성값 가져오기

                       // class ttt 아닌것 선택

                       // $("img:not(.ttt)").slideToggle(1000);

               }

        </script>

</head>

<body>

        <input type="button" value="!!!" onclick="execute();" />

        <div id="target" style="border-style: solid;">

               <img src="teayeon2.jpg" alt="태연" width="200" />

               <img src="teayeon2.jpg" alt="태연" width="200" />

        </div>

        <img src="teayeon2.jpg" alt="태연" width="80" class="ttt"/>

        <img src="teayeon2.jpg" alt="태연" width="80" class="ttt"/>

        <img src="teayeon2.jpg" alt="태연" width="80" class="ttt"/>

        <img src="teayeon2.jpg" alt="태연" width="80" class="ttt"/>

        <img src="teayeon2.jpg" alt="태연" width="80" class="ttt"/>

        <img src="teayeon2.jpg" alt="태연" width="80" class="ttt"/>

        <img src="teayeon2.jpg" alt="태연" width="80" />

        <img src="teayeon2.jpg" alt="태연" width="80" />

        <img src="teayeon2.jpg" alt="태연" width="80" />

       

</body>

</html>


② 실행화면

JQuery 1

태연 태연
태연 태연 태연 태연 태연 태연 태연 태연 태연


블로그 이미지

모데스티

,