JQuery ์ •๋ณตํ•˜๊ธฐ 1 (Library, JQuery, javascript์™€ ๋น„๊ต)

    ์ž‘๋…„์— ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ• ๋•Œ ์ž ๊น ๊ณต๋ถ€ํ•˜๊ณ  ์—ฐ์Šต ์กฐ๊ธˆ ํ–ˆ๋˜ JQuery๋ฅผ ๋‹ค์‹œ ํŒŒ๋ณด๋ ค ํ•œ๋‹ค. ๊ฑฐ์˜ ๋…ธ๋ฒ ์ด์Šค์— ๊ฐ€๊น๊ธฐ ๋•Œ๋ฌธ์— ์ด ๊ธ€์€ ์ •๋ง A๋ถ€ํ„ฐ ์‹œ์ž‘ํ•œ๋‹ค ๐Ÿฅ


    ์šฐ์„  ๋…ธํ•˜์šฐ...๋ผ๊ณ  ํ•˜๊ธด ๋„ˆ๋ฌด ๊ฑฐ์ฐฝํ•ด๋ณด์ด๋‹ˆ๊นŒ.. ๊ณต๋ถ€๋ฒ•์„ ์†Œ๊ฐœํ•ด๋ณด์ž๋ฉด ํ•„์ž๋Š” ๊ณต์‹๋ฌธ์„œ๋ฅผ ์ค‘์š”์‹œ ์—ฌ๊ธด๋‹ค. ์ฝ”๋”ฉํ•  ๋•Œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์–ธ์–ด๊ฐ€ ์˜์–ด (์šฐ๋ฆฌ ๊ต์ˆ˜๋‹˜๊ป˜์„œ ๋งŽ์ด ํ•˜์‹œ๋Š” ๋ง์”€์ด๋‹ค) ์ธ ์ด์œ ๊ฐ€ ๊ณต์‹๋ฌธ์„œ๋‚˜ ์˜์–ด๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์„œ๋ฅผ ์ฝ๊ธฐ ์œ„ํ•จ์ด๋ผ๋Š” ๋ง์ด ์žˆ๋‹ค. TMI์ง€๋งŒ ์ปด๊ณต ๊ณต๋ถ€ํ•˜๋ฉด์„œ ๊ตฌ๊ธ€๋ง๋„ ๋งŽ์ด ํ•˜๊ณ  ์˜๋ฌธ์„œ๋ฅผ ๋งŽ์ด ๋ดค๋”๋‹ˆ ์˜์–ด๊ณต๋ถ€ ํ•˜๋‚˜๋„ ์•ˆํ–ˆ๋Š”๋ฐ ํ† ์ต์ ์ˆ˜๊ฐ€ ์˜ฌ๋ž๋‹ค (..?)


    ํ•˜์ง€๋งŒ ์ ˆ๋Œ€ ๊ณต์‹๋ฌธ์„œ๋กœ ๊ณต๋ถ€๋ฅผ ์‹œ์ž‘ํ•˜์ง€ ์•Š๋Š”๋‹ค. ๊ณต๋ถ€๋ฅผ ์‹œ์ž‘ํ•˜๋ ค๋ฉด ๊ณต๋ถ€ํ•ด์•ผํ•  ๊ฒƒ์ด ๋ฌด์—‡์ธ์ง€๋ฅผ ๋จผ์ € ๊ฐ์„ ์žก์•„์•ผํ•˜๋Š”๋ฐ, ๊ณต์‹๋ฌธ์„œ์— ์ ์ธ ๋”ฑ๋”ฑํ•œ ์˜์–ด ์„ค๋ช…์œผ๋กœ๋Š” ๋‚˜์—๊ฒŒ ์™€๋‹ฟ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.


    ๊ทธ๋ž˜์„œ ๋‚œ ๊ผญ ์œ ํŠœ๋ธŒ์— ๋จผ์ € ๊ฒ€์ƒ‰์„ ํ•˜๊ณ  ์˜์ƒ ๋ช‡๊ฐœ๋ฅผ ๋ณธ ๋’ค์— ๊ณต๋ถ€๋ฅผ ์‹œ์ž‘ํ•œ๋‹ค. ์ผ์ข…์˜ ์˜ˆ์Šต์ธ ์…ˆ์ด๋‹ค. ๋งŒ์•ฝ ๊ดœ์ฐฎ์€ ๊ฐ•์˜ ์‹œ๋ฆฌ์ฆˆ๊ฐ€ ์žˆ์œผ๋ฉด ๊ทธ๊ฒƒ์„ ์ค‘์‹ฌ์œผ๋กœ ๊ณต๋ถ€ํ•˜๊ณ , ๋งŒ์•ฝ ์—†๋‹ค๋ฉด ํ•ด๋‹น ํ”Œ๋žซํผ ๋˜๋Š” ์–ธ์–ด๊ฐ€ ํŠธ๋ Œ๋“œ์ธ์ง€, ์–ด๋–จ ๋•Œ ๊ฐ•์ ์„ ๊ฐ–๋Š”์ง€, ํ˜„์—…์—์„œ ์–ด๋–ค ์‹์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ์ง€๋ฅผ ๋ฐ˜๋“œ์‹œ ์•Œ๊ณ  ๋“ค์–ด๊ฐ„๋‹ค. ์ดํ›„์— ๊ณต์‹๋ฌธ์„œ๋ฅผ ๋ณด๋ฉด ๋‚ด๊ฐ€ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•  ์ง€๋ฅผ ์ƒ๊ฐํ•˜๋ฉฐ ๊ณต๋ถ€ํ•  ์ˆ˜ ์žˆ๋‹ค.


    ์›น์•ฑ ๋ถ„์•ผ๋Š” ํŠธ๋žœ๋“œ๊ฐ€ ๋„ˆ๋ฌด๋‚˜ ๋นจ๋ฆฌ ๋ฐ”๋€Œ๊ธฐ ๋•Œ๋ฌธ์— ๋ฏธ๋ฆฌ ์‚ฌ์ „์กฐ์‚ฌ๋Š” ๋”์šฑ ํ•„์ˆ˜๋ผ๊ณ  ์ƒ๊ฐํ•œ๋‹ค. outdated๋œ ๊ฒƒ์„ ๊ณต๋ถ€ํ•  ์ˆœ ์—†์ง€!


    ๊ทธ๋Ÿฐ ์˜๋ฏธ์—์„œ JQuery์— ๋Œ€ํ•ด ์žฌ๋ฐŒ๊ฒŒ ์ฝ์—ˆ๋˜ ๊ธ€ ํ•˜๋‚˜ ๋‚จ๊ฒจ๋ณธ๋‹ค
    https://www.samsungsds.com/kr/insights/jQuery.html


    ์œ ํŠœ๋ฒ„ ์ค‘ ๊ฐ€์žฅ ์ข‹์•„ํ•˜๋Š” ๋ถ„์€ ๐Ÿง‘๐Ÿป‍๐Ÿ’ป์ƒํ™œ์ฝ”๋”ฉ๐Ÿง‘๐Ÿป‍๐Ÿ’ป๋‹˜์ด๋‹ค. ์ด๋ถ„์˜ ๊ฐ•์˜๋กœ ๊ธฐ์ดˆ๋ฅผ ํƒ„ํƒ„ํžˆ ๋‹ค์ง€๊ณ , ๋ฐ”๋กœ ๋‚ด ํ”„๋กœ์ ํŠธ์— ์‚ฌ์šฉํ•˜์—ฌ ๋ณธ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•ด๊ฐ€๋ฉฐ ์‚ฌ์ „์ฒ˜๋Ÿผ ๊ณต์‹๋ฌธ์„œ๋ฅผ ์—ด์–ด๊ฐ€๋ฉฐ ์‚ด์„ ์ฑ„์šด๋‹ค.

    ์ฐพ์•„๋ณด๋‹ˆ ์ƒํ™œ์ฝ”๋”ฉ๋‹˜์ด JQuery ๊ฐ•์˜๋ฅผ ์˜ฌ๋ ค๋‘์‹  ๊ฒŒ ์žˆ๋‹ค. ๋ฌด๋ ค 8๋…„์ „..!

    ์˜ค๋Š˜์€ ๊ทธ๊ฑธ ๋ณด๋ฉฐ ๋ฐค์ƒ˜ ๊ฐ ๐ŸŒ•! ๐ŸŒž!






    ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ž€?(library)

    ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ๋“ค์„ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ˜•ํƒœ๋กœ ๊ฐ€๊ณตํ•ด์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํšจ์œจ์„ ๋†’์—ฌ์ฃผ๋Š” ์ฝ”๋“œ๋“ค


    jQuery๋ž€?

    ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์„ ํƒํ•˜๋Š” ๊ฐ•๋ ฅํ•œ ๋ฐฉ๋ฒ•๊ณผ ์„ ํƒ๋œ ์—˜๋ฆฌ๋จผํŠธ๋“ค์„ ํšจ์œจ์ ์œผ๋กœ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋Š” ๋‹ค์–‘ํ•œ ์ˆ˜๋‹จ์„ ์ œ๊ณตํ•˜๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ


    Hello world - ์ฒซ๋ฒˆ์งธ jQuery

    ๐ŸŒž ์‚ฌ์šฉ๋ฐฉ๋ฒ•

    1. ์ง์ ‘ ์„œ๋น„์Šค ํ•˜๋Š” ๊ฒฝ์šฐ
      https://jquery.com/download/ ์—์„œ jquery ์†Œ์Šค์ฝ”๋“œ๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ•œ๋‹ค.
      ์œ„์˜ ํŒŒ์ผ์„ ์„œ๋ฒ„์— ์—…๋กœ๋“œ ํ•œ ํ›„ ์›นํŽ˜์ด์ง€ ์•ˆ์—์„œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฝ์ž…ํ•œ๋‹ค.

    1. ๊ตฌ๊ธ€์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ
      https://developers.google.com/speed/libraries#jquery
    <html>
         <body>
             <div class="welcome"></div>
             <div class="welcome"></div>
             <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
             <script type="text/javascript">
                     $('.welcome').html('hello world! coding everybody!').css('background-color','yellow');
             </script>
         </body>
     </html>



    ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์™€ jQuery ๋น„๊ต

    ํƒญ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ ํฌ์ปค์Šค๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ์˜ˆ์ œ

    ๐Ÿ‘€ JavaScript

    <html>
        <head>
            <script type="text/javascript">
                function addEvent(target, eventType,eventHandler, useCapture) {
                    if (target.addEventListener) { // W3C DOM
                        target.addEventListener(eventType,eventHandler,useCapture?useCapture:false);
                    } else if (target.attachEvent) {  // IE DOM
                        var r = target.attachEvent("on"+eventType, eventHandler);
                    }
                }
     
         
                function clickHandler(event) {
                    var nav = document.getElementById('navigation');
                    for(var i = 0; i < nav.childNodes.length; i++) {
                        var child = nav.childNodes[i];
                        if(child.nodeType==3)
                            continue;
                        child.className = '';
                    }
                    event.target.className = 'selected';
                }
      
                addEvent(window, 'load', function(eventObj) {
                    var nav = document.getElementById('navigation');
                    for(var i = 0; i < nav.childNodes.length; i++) {
                        var child = nav.childNodes[i];
                        if(child.nodeType==3)
                            continue;
                        addEvent(child, 'click', clickHandler);
                    }
                })
            </script>
            <style type="text/css">
                #navigation li {
                    list-style:none;
                    float:left;
                    padding:5px;
                }
                #navigation {
                    cursor:pointer;
                }
                #navigation .selected {
                    background-color:red;
                    color:white;
                }
            </style>
        </head>
        <body>
            <ul id="navigation">
                <li>HTML</li>
                <li>CSS</li>
                <li>javascript</li>
                <li class="selected">jQuery</li>
                <li>PHP</li>
                <li>mysql</li>
            </ul>
        </body>
    </html>
    
    
    
    

    ๐Ÿ•ต๐Ÿป‍โ™€๏ธ jQuery

    <html>
        <head>
            <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
            <script type="text/javascript">
                $('#navigation li').live('click', function() {
                    $('#navigation li').removeClass('selected');
                    $(this).addClass('selected');
                })
            </script>
            <style type="text/css">
                #navigation li {
                    list-style:none;
                    float:left;
                    padding:5px;
                }
                #navigation {
                    cursor:pointer;
                }
                #navigation .selected {
                    background-color:red;
                    color:white;
                }
            </style>
        </head>
        <body>
            <ul id="navigation">
                <li>HTML</li>
                <li>CSS</li>
                <li>javascript</li>
                <li class="selected">jQuery</li>
                <li>PHP</li>
                <li>mysql</li>
            </ul>
        </body>
    </html>
     
    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€