[Day1] JS 1 [11/18] 

 

[์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(javascript)]

   1. ๊ฐ์ฒด ๊ธฐ๋ฐ˜์˜ ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด ( OOP )

   2. ๋ชฉ์  : ์›น ํŽ˜์ด์ง€์˜ ์‚ฌ์šฉ์ž์˜ ๋ฐ˜์‘ ์ฒ˜๋ฆฌ.

               ์‚ฌ์šฉ์ž์˜ ํŠน์ • ์ด๋ฒคํŠธ๋‚˜ ์ž…๋ ฅ๊ฐ’์„ ๋ฐ›์•„์„œ ๋™์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•  ๋ชฉ์ ์œผ๋กœ 

               ๊ณ ์•ˆ๋œ ์–ธ์–ด.

   3. html5 - ์›น ํŽ˜์ด์ง€ ๊ตฌ์กฐ ์ •์˜

       css3   - ์›น ํŽ˜์ด์ง€์˜ ์Šคํƒ€์ผ ์ •์˜

       js      -   ์›น ํŽ˜์ด์ง€์˜ ๋™์ž‘ ์ฒ˜๋ฆฌ ์ •์˜  +  jquery

       

          ใ„ฑ. html ๋‚ด์šฉ ๋ณ€๊ฒฝ    days01.ex01_02.html

                - click ํ•˜๋ฉด h ๋‚ด์šฉ ๋ฐ”๋€Œ๊ฒŒ

<body onload="init();" onunload="">
<h3>ex01_02.html</h3>
๋ฉ”์‹œ์ง€ ์ž…๋ ฅ : 
<!-- autofocus="autofocus"  ์ž๋™ํฌ์ปค์Šค -->
 <!-- value="์•ˆ๋…•~~~" -->
<input type="text"  id="txtMsg"  name="txtMsg" >
<br>
<button onclick="clickme();">Click Me!</button>
<p id="demo"></p>

<script>
    var txtbox = document.getElementById("txtMsg");
  
    function init(){
    	// alert( "init()...");   ์ดˆ๊ธฐํ™”..
    	// js ๋กœ ํฌ์ปค์Šค  ์„ค์ •
    	// js  focus() ํ•จ์ˆ˜ 
    	/* 
    	document.getElementById("txtMsg").focus();
    	document.getElementById("txtMsg").value = "Hello World~";
    	 */
    	 
    	 // var txtbox = document.getElementById("txtMsg");
    	 txtbox.focus();
    	 txtbox.value = "Hello World!!!";
    }
    
    // js, jquery ๋“ฑ๋“ฑ ์ž๋™ ์™„์„ฑ...    
    function clickme(){
    	// var msg = document.getElementById("txtMsg").value;
    	var msg = txtbox.value;
    	// console.log( msg );
    	
    	// [DOM] ๋ฉ”์„œ๋“œ 
    	// document.getElementById(id);
    	// document.getElementsByClassName(name)
    	// document.getElementsByName(name)
    	var h3list =  document.getElementsByTagName("h3");  // nodelist
    	// h3.value = msg;           <h3>  value ์†์„ฑ X
    	h3list[0].innerText = msg;
    }
</script>

hover๋ฅผ js, jquery๋กœ ๊ตฌํ˜„ 

<script>
    /*
    var pdemo = document.querySelector("#demo");
    // <์‹œ์ž‘ํƒœ๊ทธ>innerText</์ข…๋ฃŒํƒœ๊ทธ> 
    //pdemo.innerText = "<span style='color:red;background-color:yellow;'>message</span>";
    pdemo.innerHTML = "<span style='color:red;background-color:yellow;'>message</span>";
    */
</script>
<script>
    /*
    var pdemo = document.querySelector("#demo");
    pdemo.onmouseover = function (){
    	// alert("dddd")
    	
    	// [1] ๋ฐฉ๋ฒ•
    	//this.style.color="red";
    	//this.style.fontSize="35px";
    	//this.style.border="1px solid gray";
    	
    	// [2] ๋ฐฉ๋ฒ•
    	// this.className = "phoverstyle";
    	// this.classList.add("phoverstyle");   // remove(), replace()
    	
    	// [3] ๋ฐฉ๋ฒ•
    	// this.setAttribute("class",  "phoverstyle");    // getAttribute("class")
    }
    */
</script>

<!-- jquery -->
<script>
    // innerText == text() jquery method
    //$("#demo").text("<span style='color:red;background-color:yellow;'>message</span>");
    
    // innerHTML == html()  jquery method
    //$("#demo").html("<span style='color:red;background-color:yellow;'>message</span>");
</script>
<script>
    /*
   $("#demo").mouseover(function() {
	   //$(this).css("color","red");
	   //$(this).css("font-size","35px");
	   //$(this).css("border","1px solid gray");
	   
	   //$(this)
       //        .css("color","red")
       //        .css("font-size","35px")
       //       .css("border","1px solid gray");
	   
	   // $(this).css("" , function (){}) 
	   // jquery.com
   }) ;
   */
   
   // on() jquery method ์ด๋ฒคํŠธ ๋“ฑ๋ก  [ + ajax ์‚ฌ์šฉ  ]
   $("#demo").on("mouseover", function() {
	   /*
	   $(this).css({
		   "์†์„ฑ๋ช…":"์†์„ฑ๊ฐ’",
		   "์†์„ฑ๋ช…":"์†์„ฑ๊ฐ’",
		   "์†์„ฑ๋ช…":"์†์„ฑ๊ฐ’",
		   "์†์„ฑ๋ช…":"์†์„ฑ๊ฐ’",
		   :
	   });
	   */
	   $(this).css({
		   "color":"red",
		   "font-size":"35px",
		   "border":"1px solid gray"
	   });
   });
   
   
</script>

          ใ„ด. html ์†์„ฑ ๋ณ€๊ฒฝ   ex01_03.html

                - Turn on ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์ „๊ตฌ์— ๋ถˆ์„ ์ผœ๋„๋ก ํ•  ์˜ˆ์ •

                -  img ์š”์†Œ์˜  src ์†์„ฑ์„ ../images/pic_bulbon.gif   ๋ณ€๊ฒฝ

                        alt ์†์„ฑ ="bulbon"

<!-- ๋ฌธ์ œ 2 ํ’€์ด -->
	<button>Turn on</button>
	<button disabled="disabled">Turn off</button>

	<br>
	<img src="../images/pic_bulboff.gif" alt="" id="bulb">

	<!-- js -->
	<script>
	    /*
		// Turn on ๋ฒ„ํŠผ
		//  document.querySelector("button:first-of-type")
		document.querySelector("button:nth-of-type(1)").onclick = function() {
			// alert( "aaa") ์ด๋ฒคํŠธ ํ™•์ธ
			// js ๋ณ€์ˆ˜ ์„ ์–ธ ํ‚ค์›Œ๋“œ :  var,  let
			let bulb = document.getElementById("bulb");
			bulb.src = "../images/pic_bulbon.gif";
			// bulb.alt = "bulbon";
			bulb.setAttribute("alt", "bulbon");

			// turn on ๋ฒ„ํŠผ ๋น„ํ™œ์„ฑํ™”
			document.querySelector("button:first-of-type").disabled = true;
			// turn off ๋ฒ„ํŠผ ํ™œ์„ฑํ™”
			document.querySelector("button:last-of-type").disabled = false;
		}

		// Turn off ๋ฒ„ํŠผ
		document.querySelector("button:last-of-type").onclick = function() {
			//console.log( "bbb");  ์ด๋ฒคํŠธ ํ™•์ธ
			let bulb = document.getElementById("bulb");
			bulb.src = "../images/pic_bulboff.gif";
			bulb.setAttribute("alt", "bulboff");

			// turn on ๋ฒ„ํŠผ ํ™œ์„ฑํ™”
			document.querySelector("button:first-of-type").disabled = false;
			// turn off ๋ฒ„ํŠผ ๋น„ํ™œ์„ฑํ™”
			document.querySelector("button:last-of-type").disabled = true;
		}
		*/
	</script>

	<!-- jquery -->
	<script>
		// Turn on ๋ฒ„ํŠผ		
		$("button:nth-of-type(1)").click(function() {			
			// jquery method :  attr()
			/*
			$("#bulb")
			     .attr("src", "../images/pic_bulbon.gif")
			     .attr("alt", "bulbon"); 
			*/
			$("#bulb")
			     .attr({
							src: "../images/pic_bulbon.gif",
							alt:"bulbon"
						});
			
			
			// attr() / prop() / is(:checked)
			//$(this).prop("disabled", true);
			// next() ๋‹ค์Œ์š”์†Œ
			//$(this).next().prop("disabled", false); 
			
			$(this)
			     .prop("disabled", true)
			     .next()
			         .prop("disabled", false); 
			
		})		 

		// Turn off ๋ฒ„ํŠผ
		$("button:nth-of-type(2)").click(function() {			 
			$("#bulb")
			        .attr({
							src: "../images/pic_bulboff.gif",
							alt:"bulboff"
			          });
			
			$(this)
			     .prop("disabled", true)
			     .prev()
			         .prop("disabled", false); 
			
		})		 
	</script>
	<h3>ex01_04.html - [ js ]html ์†์„ฑ ๋ณ€๊ฒฝ</h3>
	<pre>
         [Turn on]  ํด๋ฆญํ•˜๋ฉด   [Turn off]       ์ „๊ตฌ ๋ถˆ ON
         [Turn off]  ํด๋ฆญํ•˜๋ฉด   [Turn on]       ์ „๊ตฌ ๋ถˆ OFF
    </pre>
	<!-- ๋ฌธ์ œ 2 ํ’€์ด -->
	<button>Turn on</button>

	<br>
	<img src="../images/pic_bulboff.gif" alt="" id="bulb">

	<!-- js -->
	<script>	   
	  /*
	   document.querySelector("button").onclick = function (){
		    // alert( this.innerText );		    alert( this.innerHTML );
		    let bulb = document.getElementById("bulb");
		    var text = this.innerText;
		    
		    if( text == "Turn on"){ // js     if~else                   equals()		    	 
				bulb.src = "../images/pic_bulbon.gif";
				this.innerText = "Turn off";
		    }else{		    	
				bulb.src = "../images/pic_bulboff.gif";
				this.innerText = "Turn on";
		    } // if
		    
	   }
	*/
	</script>
	<script>	  
	   /*
	   // ์Šค์œ„์น˜ ๋ณ€์ˆ˜ ์‚ฌ์šฉ
	   var sw = false;
	   let bulb = document.getElementById("bulb");
	   
	   document.querySelector("button").onclick = function (){		  
	 
		   // if( !sw ){ 		    	 
		   //	bulb.src = "../images/pic_bulbon.gif";
		   // }else{		    	
		   //	bulb.src = "../images/pic_bulboff.gif";
		   // } // if
		  
		    // js ์‚ผํ•ญ์—ฐ์‚ฐ์ž  ? :
		    //  bulb.src =   sw ? "../images/pic_bulboff.gif" : "../images/pic_bulbon.gif";
		    bulb.src = "../images/pic_bulb" +  ( sw ? "off" : "on" ) + ".gif";		    
		    this.innerText =   sw ?   "Turn on" : "Turn off"; 
		    sw = !sw;
	   } 
	   */
	</script>

 

         ใ„ท. html ์Šคํƒ€์ผ(css)  ๋ณ€๊ฒฝ

          ใ„น. html ์š”์†Œ ์ˆจ๊ธฐ๊ธฐ/๋ณด์ด๊ธฐ

          ๋“ฑ๋“ฑ

     4. ์‚ฌ์šฉ์ž ๊ฒฝํ—˜   ( UX ) / UI ์„ ํ–ฅ์ƒ์‹œํ‚ค๊ธฐ ์œ„ํ•œ ๋ฐฉ๋ฒ• : js ์ฃผ๋กœ ์‚ฌ์šฉ. 

     5. js = ์›น๋ธŒ๋ผ์šฐ์ €(ํด๋ผ์ด์–ธํŠธ) ์–ธ์–ด  + ์ง€๊ธˆ์€ ์„œ๋น„ ์ธก ํ”„๋กœ๊ทธ๋žจ ๊ฐœ๋ฐœ ์‚ฌ์šฉ( ํ™•๋Œ€ )

                                                               node.js

     6. js ๋‹ค์šด๋กœ๋“œ X / ์„ค์น˜ X => ๋ธŒ๋ผ์šฐ์ € ๋‚ด์žฅ( js ์—”์ง„ )

                                              ๋ธŒ๋ผ์šฐ์ € ์ข…๋ฅ˜ / ๋ฒ„์ „  js X

     7. ํ‘œ์ค€ js  ๋Š”  ECMAScript  ( ์—ํฌ๋งˆ ์Šคํฌ๋ฆฝํŠธ)

         ํ‘œ์ค€ ๊ณต์‹ ์ด๋ฆ„ : ECMA-262

     8. js๋Š”       <script></script> (๋ฐ”๋””, ํ—ค๋“œ ์•ˆ์— ๊ถŒ์žฅ)

     9. <script></script> ํƒœ๊ทธ๋Š” ์›ํ•˜๋Š” ์œ„์น˜์— ์›ํ•˜๋Š” ์ˆ˜๋งŒํผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. 

         ex03.html      

         

     10. ๋™์ผํ•œ js ์ฝ”๋”ฉ์ด ์—ฌ๋Ÿฌ ํŽ˜์ด์ง€์— ๋ฐ˜๋ณต์ ์œผ๋กœ ์‚ฌ์šฉ๋œ๋‹ค๋ฉด 

          ์™ธ๋ถ€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ( ??????.js ) ์‚ฌ์šฉ.        

<script src="ex01_myscript.js"></script>

/**
 *  ex01_myscript.js
 */
 
 function myAlert( name ){
     alert(  name +"๋‹˜ ํ™˜์˜~~" );
 }

         - ์™ธ๋ถ€ js ํŒŒ์ผ ์‚ฌ์šฉ ์žฅ์ 

            1) html ์ฝ”๋”ฉ +  js ์ฝ”๋”ฉ ๋ถ„๋ฆฌ -> ๋” ์‰ฝ๊ฒŒ ์ฝ๊ณ  ์œ ์ง€ ๋ณด์ˆ˜ ๊ฐ€๋Šฅ

            2) ์บ์‹ฑ๋œ js ํŒŒ์ผ์€ ํŽ˜์ด์ง€๋ฅผ ๋กœ๋”ฉ ์†๋„ ๋” ํ–ฅ์ƒ. 

         -  ์™ธ๋ถ€ js ํŒŒ์ผ 3๊ฐ€์ง€ ๋ฐฉ๋ฒ•

            1)  ์ „์ฒด URL

                https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js

            2) ํŒŒ์ผ ๊ฒฝ๋กœ

                 ../js/myscript.js

            3) ๊ฐ™์€ ๊ฒฝ๋กœ

                myscript.js  

          

     11. body ์š”์†Œ ๋งจ ์•„๋ž˜์— scirpt ๋ฅผ ๋ฐฐ์น˜ํ•˜๋ฉด    ํ™”๋ฉด ์ถœ๋ ฅํ•˜๋Š” ์†๋„๊ฐ€ ํ–ฅ์ƒ๋œ๋‹ค.     

 

*autofocus ์—†์—ˆ์„๋•Œ body onload

* getElements VS element


๋ฌธ์ œ 4๋ฒˆ ํ’€์ด : ๋ผ๋””์˜ค์ฒดํฌ

<fieldset>
   <legend>html ์ ์šฉ์—ฌ๋ถ€</legend>
   <input type="radio"  name="htmlAppy" checked="checked"  value="apply"><label>์ ์šฉ</label>
   <input type="radio"  name="htmlAppy"  value="not apply"><label>๋น„์ ์šฉ</label>
</fieldset>
<input type="text" value="<b>ํ™๊ธธ๋™</b>">
<br>
<button>ํ™•์ธ</button>
<p id="demo"></p>
<!-- js -->
<script>
     /*
    document.querySelector("button").onclick = function (){
    	// document.getElementsByName("htmlAppy");
    	var rdbs =  document.querySelectorAll("fieldset > input[type=radio]");
    	// alert( rdbs.length );
    	// ๋ผ๋””์˜ค๋ฒ„ํŠผ 1๊ฐœ๋งŒ ์ฒดํฌ.
    	var txtValue = document.querySelector("input[type=text]").value;
    	if (  rdbs[0].checked  ) {  // ์ ์šฉ 
    		document.querySelector("#demo").innerHTML = txtValue ;
		} else {  // ๋น„์ ์šฉ
			document.querySelector("#demo").innerText = txtValue;
		}
    }
     */
</script>

<!-- jquery -->
<script>

   $("button").click(function (){
	    var rdbs =  $("fieldset > input[type=radio]");
	    var txtValue = $("input[type=text]").val();
	    if (  rdbs[0].checked  ) {  // ์ ์šฉ   attr()/prop()/is()
			$("#demo").html( txtValue );
		} else {  // ๋น„์ ์šฉ
			$("#demo").text( txtValue );
		}
   }); 
 
</script>

[js ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ ๊ธฐ๋Šฅ]

   1. document.write();

   2. window.alert("") ;    - ๊ฒฝ๊ณ ์ฐฝ์œผ๋กœ ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ

       alert("");

   3. console.log()  - ๋ธŒ๋ผ์šฐ์ € ์ฝ˜์†” ์ฐฝ์— ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ( ๋””๋ฒ„๊น… ๋ชฉ์  )

   4. ์š”์†Œ.innerText  ์†์„ฑ         -> text()

       ์š”์†Œ.innerHTML ์†์„ฑ        -> html()


๋ฌธ์ œ6

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<style>
   .active{
      background-color: yellow;
      color:rgb(206, 233, 96);
      font-size: 25px;
   }
</style>
</head>
<body>

์ข‹์•„ํ•˜๋Š” ๊ณผ๋ชฉ ์„ ํƒ?
<br>
 
<input type="checkbox" value="kor"  name="subject"  id="s_kor" ><label for="s_kor">๊ตญ์–ด</label>
<input type="checkbox" value="eng"  name="subject"  id="s_eng"  checked="checked"><label for="s_eng">์˜์–ด</label>
<input type="checkbox" value="mat"  name="subject"  id="s_mat" ><label for="s_mat">์ˆ˜ํ•™</label>
<input type="checkbox" value="pe"  name="subject"  id="s_pe" ><label for="s_pe">์ฒด์œก</label>
 
 <br>
 <br>
 <button onclick="">ํ™•์ธ</button> 
 <p id="demo"></p>

<!-- js -->
<script>
     /*
     document.querySelector("button").onclick = function (){
    	 document.getElementById("demo").innerHTML = "";
    	  // alert("์ด๋ฒคํŠธ ํ™•์ธ")
    	 //var ckbs = document.querySelectorAll("input[type=checkbox][name=subject]");
    	 //var ckbs = document.querySelectorAll("[name=subject]");
    	 var ckbs = document.getElementsByName("subject");
    	 // alert( ckbs.length ); 
    	 var content = "";
    	 for (var i = 0; i < ckbs.length; i++) {
    		  if(  ckbs[i].checked ){
    			  // console.log( ckbs[i].value );
    			  //document.getElementById("demo").innerHTML += ckbs[i].value+"<br>";
    			  if( ckbs[i].value == "kor" ){
    				  content += 	"<b class='active'>"+ ckbs[i].value+"</b><br>";   
    			  }else{
    				  content += 	"<b>"+ ckbs[i].value+"</b><br>";   
    			  }
    		       
    		  }
		  } // for
		  
    	 document.getElementById("demo").innerHTML =  content;
     }
     */
</script>

<!-- jquery -->
<script>
     /*
    $("button").click( function (){
    	$("#demo").html("");    	
    	// $("[name=subject]")
    	
    	//  jquery selector -   :checkbox
    	//  $(":checkbox") ==$("input[type=checkbox]")
    	var ckbs = $(":checkbox[name=subject]");
    	// alert( ckbs.length );
    	for (var i = 0; i < ckbs.length; i++) {
    		  //if ( elem.checked )                            - js
    		  //if ( $( elem ).prop( "checked" ) )
    		  //if ( $( elem ).is( ":checked" ) )
    			  
    		 // 	  Uncaught TypeError: ckbs[i].prop is not a function
    		 //   jquery object =   jquery method : prop(), val(), ....
    		 //  *** $(html element) -> jquery object ๋ณ€ํ™˜ ***
    		 if( $(ckbs[i]).prop( "checked" ) ){
                //    	     	  Uncaught TypeError: ckbs[i].val is not a function
    			 //  console.log( $(ckbs[i]).val()  );    // val() ๋ฉ”์„œ๋“œ == value ์†์„ฑ
    			 
    			 // $("#demo").html(  $("#demo").html() +   $(ckbs[i]).val() +"<br>"    );    			 
    			 $("#demo").html( function (index, oldhtml){
    				 return oldhtml +"<br>" + $(ckbs[i]).val();
    			 } );
    			 
    		  }	   // if
		} //for 
    	
    } );
    */
</script>

<!-- jquery ๋‘ ๋ฒˆ์งธ ๋ฐฉ๋ฒ• -->
<script>
$("button").click(  function (){
	$("#demo").html("");
	// ์ฒดํฌ๋ฐ•์Šค ์ค‘์— ์ฒดํฌ๋œ ์ฒดํฌ ๋ฐ•์Šค๋ฅผ ์–ป์–ด์˜ค๋Š” ๊ฒƒ.	
	/* jquery selector -  :checked */
	
	// ๋ฐ˜๋ณต๋ฌธ - value ์–ป์–ด์™€์„œ -> #demo ์ถœ๋ ฅ
	// jquery method -   each()
	$("[name=subject]:checked").each(function (index, element){
		                                   //    element.val()
		// console.log( index +" / " + element.value + " / " + $(element).val()  +" / " + $(this).val() );
         $("#demo").html( function (index, oldhtml){
        	 return oldhtml +"<br>" + $(element).next().text();
         });		                                   
	});
	
} );
</script>

* jquery ๊ฐ์ฒด๋งŒ .prop ์‚ฌ์šฉ๊ฐ€๋Šฅ (๋ณ€ํ™˜์‹œ์ผœ์•ผํ•จ) 


1.  option์„ ์„ ํƒํ•˜๊ฒŒ๋˜๋ฉด ์ผ์–ด๋‚˜๋Š” ์ด๋ฒคํŠธ - [ change ์ด๋ฒคํŠธ ] 

  2. ์—ฌ๋Ÿฌ option ๋“ค ์ค‘์— ์–ด๋–ค option์ด ์„ ํƒ 

       - selectedIndex ์†์„ฑ

  3. ์„ ํƒ๋œ option์˜ value, text 

       select.options[selectedIndex].value,   .text ์ปฌ๋ ‰์…˜     

       

    ์ฃผ์˜)    ์„ ํƒ๋œ ์˜ต์…˜์„ ๋‹ค์‹œ ์„ ํƒํ•˜๋ฉด chage ์ด๋ฒคํŠธ๋Š” ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค. 

<br>
<!-- select>option*5 -->
<!-- select ์š”์†Œ์—์„œ text ์†์„ฑ๋งŒ ์„ค์ •ํ•˜๋Š” value ์†์„ฑ์€ ๋™์ผํ•œ ๊ฐ’. -->
<select name="subject" id="subject">
	<option value="">์„ ํƒํ•˜์„ธ์š”.</option>
	<option value="kor">๊ตญ์–ด</option>
	<option value="eng">์˜์–ด</option>
	<option value="mat">์ˆ˜ํ•™</option>
	<option value="pe">์ฒด์œก</option>
</select>
 
<br>
<p id="demo"></p>

<!-- js -->
<script>
     /*
    document.getElementById("subject").onchange= function (){
    	// console.log( "change event ~");
    	// console.log(  this.selectedIndex );
    	var index = this.selectedIndex;
    	var op = this.options[index];
    	if( op.value == 0 ) {
    		alert("์„ ํƒํ•˜์„ธ์š”~~")
    	}else{
    		console.log(  op.value + " / " +  op.text );	
    	}    	
    }
     */
</script>
<script>
    /*
    //                                      kor - undefined
	document.getElementById("subject").onchange= function (){
		 console.log(   this.value  + " - " + this.text  );
	}
    */
</script>

<!--  jquery -->
<script>
    // alert( $("#subject option").length );
    // alert( $("#subject option").size() );  X

    $("#subject").change(function() {
    	// console.log(  $(this).val() +" // " + $(this).text()  );
    	
    	// jquery selector  -   :checked,         :selected
    	// console.log(  $("#subject option:selected").text()  );
    	
    	// jquery method -  find()
    	console.log(  $(this).val() +" // " + $(this).find(":selected").text()  );
    	
    	// http://erel.kr/bbs/board.php?bo_table=study&wr_id=275
    });
</script>

  1.  js ์ฝ”๋”ฉ์„ ๋ˆ„๊ฐ€ ์‹คํ–‰ ? ์›น ๋ธŒ๋ผ์šฐ์ €(*** ํด๋ผ์ด์–ธํŠธ ***))๊ฐ€ ์‹คํ–‰.

  2. ์ž‘์„ฑ๋œ ์ˆœ์„œ๋Œ€๋กœ ํ•˜๋‚˜์”ฉ ์‹คํ–‰๋œ๋‹ค. 

  3. ์‹คํ–‰๋ฌธ(๋ช…๋ น๋ฌธ) ๋’ค์— ์„ธ๋ฏธ์ฝœ๋ก ์„ ์ถ”๊ฐ€.

      js ๋Š” ์„ธ๋ฏธ์ฝœ๋ก  ์•ˆ ์ฐ์–ด๋„ ๋œ๋‹ค. 

      ํ•˜์ง€๋งŒ  ์„ธ๋ฏธ์ฝœ๋ก ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์„ ( ์ ๊ทน๊ถŒ์žฅ )ํ•œ๋‹ค.

  4. js ๋Š” ์—ฌ๋Ÿฌ ๊ณต๋ฐฑ์„ ๋ฌด์‹œํ•œ๋‹ค.

       ๊ณต๋ฐฑ์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๊ฐ€๋…์„ฑ์ด ์ข‹๋‹ค. 

       var name = xx;

       var sum = m + l + x;      

   5. js ์˜ˆ์•ฝ์–ด(ํ‚ค์›Œ๋“œ)    

       var

       let 

       const ํ‚ค์›Œ๋“œ == ์ƒ์ˆ˜ ์„ ์–ธ.            ( final double PI = 3.14)

       if

       for

       function 

       

       abstract arguments await* boolean

break byte case catch

char class* const continue

debugger default delete do

double else enum* eval

export* extends* false final

finally float for function

goto if implements import*

in instanceof int interface

let* long native new

null package private protected

public return short static

super* switch synchronized this

throw throws transient true

try typeof var void

volatile while with yield

       

      6. ๋ฆฌํ„ฐ๋Ÿด(  ๊ณ ์ •๊ฐ’ )

         3.14          'A'           [ "admin"          'admin'  ]         true   false ๋“ฑ๋“ฑ

         

      7.   js ๋Š” ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•œ๋‹ค.   

      8.   js์˜ ๋ณ€์ˆ˜ ์„ ์–ธ ํ˜•์‹ :                 firstNameName

                                                         getFirstName

                                                         ์บ๋ฉ€ํ‘œ๊ธฐ๋ฒ•

      9. js ์‹๋ณ„์ž ๋ช…๋ช…ํ•˜๋Š” ๊ทœ์น™        

      

      10. js ์ฃผ์„์ฒ˜๋ฆฌ        //                         /*~ */      

 

  /*
  var                          name     = 'admin'         ;
  var age    =                           10;
  
  Age = 20;
  */
  
  
  //var name = "John Doe";
  //var name = 'John Doe';
  var name = "John's Doe";
  
  // js๋Š” ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜์ง€ ์•Š๊ณ  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  Name = "admin";
  
 alert(   name  + " / " +  Name );

   [ js ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋Š” 4๊ฐ€์ง€ ๋ฐฉ๋ฒ• ]

   1. var  : 1995๋…„ ~ 2015๋…„ ๊นŒ์ง€ js ์ฝ”๋“œ์—์„œ ์‚ฌ์šฉ.

   2. let   : 2015๋…„( ES6 )   js ์ถ”๊ฐ€๋œ ํ‚ค์›Œ๋“œ

   3. const :   ์ƒ์ˆ˜ํ™”( ๋ณ€์ˆ˜๊ฐ’์„ ๋ณ€๊ฒฝ X )

   4. ์•„๋ฌด๊ฒƒ๋„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ

'๐Ÿ‘จโ€๐Ÿ’ป Web Development > HTML | CSS | JS | jQuery' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Day3] JS 3 - ํ…Œ์ด๋ธ”์ฒดํฌ, ํ•จ์ˆ˜, undefined, null, ๊ฐ์ฒด, ์—„๊ฒฉ๋ชจ๋“œ, this, ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ, ๋ฌธ์ž์—ด  (0) 2022.11.22
[Day2] JS 2 - ๋ณ€์ˆ˜, ์—ฐ์‚ฐ์ž, ์ž๋ฃŒํ˜•, ํ‚ค๋ณด๋“œ  (0) 2022.11.22
[Day6] CSS 6 - ํ…์ŠคํŠธํšจ๊ณผ, ์›น๊ธ€๊ผด, 2D 3D, ์ „ํ™˜, ์• ๋‹ˆ๋ฉ”์ด์…˜, ํˆดํŒ, ๋ทฐํฌํŠธ, ๋ฏธ๋””์–ด์ฟผ๋ฆฌ  (0) 2022.11.18
[Day5] CSS 5 - ๋กค์˜ค๋ฒ„, ๋ฉ”๋‰ด๋ฐ”, ํƒ€์ž„๋ผ์ธ, ์ด๋ฏธ์ง€ ๊ฐค๋Ÿฌ๋ฆฌ, ์ด๋ฏธ์ง€ ์Šคํ”„๋ผ์ดํŠธ, ์„ ํƒ์ž, ๊ฒ€์ƒ‰์Šคํƒ€์ผ, ํ‰์ , ํŠน์ด์„ฑ(์ ์ˆ˜), ๋ง‰๋Œ€๊ทธ๋ž˜ํ”„, ํ”„๋กœํ•„, ๋‘ฅ๊ทผ๋ชจ์„œ๋ฆฌ, ๋‹ค์ค‘๋ฐฐ๊ฒฝ์ด๋ฏธ์ง€, background image, paral..  (0) 2022.11.17
[Day4] CSS 4 - overflow, ํŒ์—…ํผ, display, prev|next, ๋ ˆ์ด์•„์›ƒ๋ฐฐ์น˜(์ˆ˜์ง์ˆ˜ํ‰), css๊ฒฐํ•ฉ์ž, ์˜์‚ฌํด๋ž˜์Šค, ์˜์‚ฌ์š”์†Œ, ๋ถˆํˆฌ๋ช…, ํƒ์ƒ‰๋ชจ๋“ฌ, ๋“œ๋กญ๋‹ค์šด  (0) 2022.11.16
  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ