[Day2] jQuery 2 [11/30] 

 

--๋ณต์Šต--

๊ฐ™์€ ์ฝ”๋”ฉ

     $(document).ready(function (){
     });
  
      $(function (){
      });         
      $( jq selector).action();

[jquery  ํšจ๊ณผ ]

- ์ˆจ๊ธฐ๊ธฐ, ํ‘œ๊ธฐ,  ํ† ๊ธ€ , ์Šฌ๋ผ์ด๋“œ, ํŽ˜์ด๋“œ , ์• ๋‹ˆ๋ฉ”์ด์…˜... ๋“ฑ๋“ฑ

- hide(), show()

 

๋ชจ๋“  pํƒœ๊ทธ ์ˆจ๊ธฐ๊ธฐ

  <button>show</button>
  <button>toggle</button>
  
  
  <!-- p*5>lorem5 -->
  <p>1. Lorem ipsum dolor sit amet.</p>
  <p  style="display: none;">2. Sunt hic repudiandae sed reiciendis!</p>
  <p>3. Nulla ab nobis ea reprehenderit?</p>
  <p  style="display: none;">4. Deserunt nam enim ut accusamus.</p>
  <p>5. Minima sunt amet perferendis excepturi.</p>
  <script>
       $(function (){
    	   $("button").last().click(function (){
    		   // show() -> hide()
    		   // hide() -> show()
    		   // ํ† ๊ธ€ ๊ธฐ๋Šฅ
    		   $("p").toggle(600);  
    	   } );
       });
  </script>
  
  
<script>
   $(function (){
	   //                 css selector  -> jquery selector  +  ์•ŒํŒŒ
	   //$("button:nth-of-type(1)")
	   //$("button:first-of-type")
	   //$("button:eq(0)")
	   // $("button").first().click( function (){
	   $("body").find("button").eq(0).click(  function (){
		    // alert("2")
		    // ๋ชจ๋“  p ํƒœ๊ทธ
		    // $("p").hide();
		   // $("p").hide(400);
		   $("p").hide("slow" , function (){
			      alert("์ˆจ๊ธฐ๊ธฐ ์™„๋ฃŒ!!")
			});  // "fast"
	   });
   });
</script>

* ๋ฒ„ํŠผ ์ฐพ๊ธฐ ๋งŽ์€ ๋ฐฉ๋ฒ•์ด ์žˆ์Œ

 

<a href="http://www.daum.net">daum</a>
    // ์œ„์˜ daum ๋งํฌํƒœ๊ทธ๋ฅผ ํด๋ฆญํ•  ๋•Œ 
    // ๊ทธ ๋งํฌ ํƒœ๊ทธ๋ฅผ ์ˆจ๊ฒจ๋ผ..
    // a ๋งํฌ ํƒœ๊ทธ์˜ ๊ธฐ๋ณธ ๊ธฐ๋Šฅ์ด ํŽ˜์ด์ง€ ์ด๋™.(์—ฐ๊ฒฐ)
    $("a").click( function (event){
    	// $(this).href = "#";
    	// this.href = "#";  // (๊ณ ๋ฏผ)  href ์†์„ฑ X
    	event.preventDefault();  // ( ๊ธฐ์–ต )
    	// submit
    	$(this).hide();
    });

* ๋งํฌ๋ฅผ ์•ˆ๋จน๊ฒŒํ•˜๊ณ  hide (#์œผ๋กœ ๋‘๊ฑฐ๋‚˜ event.preventDefault()๋„ ๊ฐ€๋Šฅ)

 

+fade, fadeTo, slidedown, slideup, slidetodggle, animate(์• ๋‹ˆ๋ฉ”์ด์…˜ ํ ์ œ๊ณต), 

(jquery days02 ์ฐธ๊ณ )


์ฝœ๋ฐฑํ•จ์ˆ˜ : ์ž‘์—…ํ•œ ์‚ฌ๋žŒ์ด ์ž‘์—… ์™„๋ฃŒํ–ˆ๋‹ค๋Š” ๊ฒƒ์„ ํ˜ธ์ถœํ•ด์„œ ์•Œ๋ ค์ง€๋Š” ํ•จ์ˆ˜ (์ž‘์—…์ด ๋๋‚œ ํ›„ ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜)

<button>hide</button>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. 
Quibusdam dolorem soluta accusamus sint atque explicabo 
nesciunt consequatur beatae quae fuga excepturi corrupti 
tempora commodi enim nulla deleniti magni provident? 
Vitae.</p>
  $(function (){
	  $("button").click( function (){
		  // 1. p ์ˆจ๊ธฐ๊ธฐ. (3์ดˆ)
		  // 2. p ์™„์ „ํžˆ ์ˆจ๊ธฐ์ง„ ํ›„์— ๊ฒฝ๊ณ ์ฐฝ ๋„์šฐ๊ธฐ๋ฅผ...
		  /*
		  $("p").hide(3000);
		  alert("์™„์ „ํžˆ ์ˆจ๊ฒจ์Šต๋‹ˆ๋‹ค.")
		  */
		  $("p").hide(3000, function (){
			  // ์ฝœ๋ฐฑํ•จ์ˆ˜
			  alert("์™„์ „ํžˆ ์ˆจ๊ฒจ์Šต๋‹ˆ๋‹ค.")
		  });
	  });
  });

* hide(3000, ์—ฌ๊ธฐ ์˜ค๋Š”๊ฒŒ ์ฝœ๋ฐฑํ•จ์ˆ˜)


jquery selector

   1.   *        ๋ชจ๋“  ์š”์†Œ๋“ค             ex02_02.html

   2. #id

   3. .class

   4.   .class, .class

   5. element

   6. :first                               ex02_03.html

       :last

   7. :even ์ง์ˆ˜  0,2,4                               ex02_04.html

       :odd  ํ™€์ˆ˜   1,3,5..

       

    8.  :first-child                            ex02_05.html

         :last-child

   // ๋ชจ๋“  p ํƒœ๊ทธ  : ๋ฐฐ๊ฒฝ์ƒ‰ = ๋…ธ๋ž‘
   // $("p").css("background-color", "yellow");
   
   // ์ฒซ ๋ฒˆ์งธ p ํƒœ๊ทธ์˜ ๋ฐฐ๊ฒฝ์ƒ‰ = ๋…ธ๋ž‘
   // jquery selectors 
   // first() : jquery method
   // last() : jquery method
   // eq(index) : jquery method
   
   // $("p").first().css("background-color", "yellow");
   $("p:first").css("background-color", "red");
   $("p:last").css("background-color", "blue");

* ํ•จ์ˆ˜, ํƒœ๊ทธ ์ฐจ์ด

 

         :first-of-type

         :last - of-type  

    $(function (){
    	$("#btn1").click( function (){
        	// $("p").css("background-color","yellow");
        	
        	// :first   ์„ ํƒ์ž :  ๋ชจ๋“  p ํƒœ๊ทธ ์ค‘์— ์ฒซ ๋ฒˆ์งธ p ํƒœ๊ทธ...
    		$("p:first").css("background-color","red");
        });	// btn1_click
        
        $("#btn2").click( function (){ 
        	// ์–ด๋–ค ์š”์†Œ์˜  ์ž์‹(child)์š”์†Œ ์ค‘์— ์ฒซ ๋ฒˆ์งธ ์ž์‹์ด p ์ธ ์„ ํƒ์ž.
    		$("p:first-child").css("background-color","green");
        });	// btn2_click
        
        $("#btn3").click( function (){ 
        	//  ์–ด๋–ค ์š”์†Œ์˜ ์ฒ˜์Œ ์ธ  p ํƒœ๊ทธ
    		$("p:first-of-type").css("background-color","blue");
        });	// btn3_click
        
    }); // ready

* first-child : ์ž์‹์š”์†Œ ์ค‘ ์ฒซ๋ฒˆ์งธ๊ฐ€ p ๋ฉด ํ•ด๋‹น

* first-of-type : ์ž์‹์š”์†Œ ์ค‘ ์ฒ˜์Œ์œผ๋กœ ์˜ค๋Š” p๊ฐ€ ํ•ด๋‹น 

 

    9.  :nth-child(n)                    ex02_06.html

         :nth-last-child(n)

         

         jquery method   nth-of-type()

         

         :nth-of-type(n)

         :nth-last-of-type(n)  

         

   10. :only-child                ex02_07.html

        :only-of-type      

        

   11.                                    ex02_08.html

         parent > child   : ์ง๊ณ„์ž์‹๋งŒ

         parent   child     : ์ง๊ณ„์ž์‹ + ํ›„์†

         parent + child    :  div ๋‹ค์Œ ํ˜•์ œํƒœ๊ทธ๊ฐ€ p

         parent ~ child    : div ๋’ค์— ๋”ฐ๋ผ์˜ค๋Š” p ํƒœ๊ทธ์ธ๋ฐ ๋ฐ”๋กœ๋’ค ์•„๋‹ˆ๋”๋ผ๋„ ์ƒ๊ด€์—†์Œ (๋ชจ๋“  ํ˜•์ œํƒœ๊ทธ์ธ p)

         

    12.  

           eq(์–‘์ˆ˜, ์Œ์ˆ˜ index)

           :eq(index)  ==              ex02_09.html

          :gt(no)  >

          :lt(no)   <     

          

     13.     :not(selector)            ex02_10.html

              not()  jquery method

          

     14.    :header                   ex02_11.html

     

     15.  :animated                 ex02_12.html

              ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ง„ํ–‰์ค‘์ธ  ๋ชจ๋“  ์š”์†Œ

              

      16.         :focus               ex02_13.html     

                   :text              <input type="text">         

                

      17.         :has(selector)      ex02_14.html

                       ๊ฐ€์ง€๋‹ค.

                               

      18.        :contains(  text string )       ex02_14.html

                      ํฌํ•จํ•˜๋‹ค.          

                          

      19.       :empty                                    ex02_15.html       

      20.      :parent      ๋ถ€๋ชจ( ์ž์‹ )

                     ๋‹ค๋ฅธ ์š”์†Œ์˜ ๋ถ€๋ชจ๊ฐ€ ๋˜๋Š” ๋ชจ๋“  ์š”์†Œ     

       

      21.     :hidden                                      ex02_16.html

                :visible

              

       22.  :root                 

               document.documentElement

               ๋ฃจํŠธ ์—˜๋ฆฌ๋จผํŠธ 

               html ์š”์†Œ      

               

      23.  :lang(  language )

              lang ์†์„ฑ..

              

              css selector < jquery selector

     24.                                                       ex02_17.html

                [attribute]                                      

                [attribute=value]                                      

                [attribute!=value]                                      

                [attribute*=value]                                      

                [attribute$=value]                                      

                [attribute^=value]                                      

                [attribute~=value]                                      

                

                [attribute|=value]  X          

        

       25.         

                :disabled

                :enabled       

                :input          == <input>   ๋ชจ๋“  input ํƒœ๊ทธ   

                :text           ==   input[type=text]          

                :radio         == input[type=radid]        

                :password  ==  input[type=password]

                :chcekbox  ==  input[type=checkbox]

                :submit  ==  input[type=submit]

                :reset  ==  input[type=reset]

                :image  ==  input[type=image]

                :file  ==  input[type=file]

                :button  ==  input[type=button]

                

                :checked     =  ์ฒดํฌ๋œ input ํƒœ๊ทธ 

                :selected         <option  selected=selected>

                

         //       $(selector).action()

  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ