๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
JQUERY

[JAVASCRIPT] JQUERY ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ž€?

by _ํ† ๋งคํ†  2022. 8. 30.
728x90

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ : Jquery ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ธ jquery์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.๐Ÿ˜†


#1. Jquery๋ž€?

JQuery๋กœ HTML์˜ ์š”์†Œ๋“ค์„ ์‰ฝ๊ฒŒ ์กฐ์ž‘ํ•˜๊ณ  ํŽธ๋ฆฌํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ Javascript๋ฅผ ๋ฏธ๋ฆฌ ์ž‘์„ฑํ•ด๋‘” ๊ฒƒ์ž…๋‹ˆ๋‹ค. Javascript๋กœ ๊ธธ๊ณ  ๋ณต์žกํ•˜๊ฒŒ ์จ์•ผ ํ•˜๋Š” ๊ฒƒ์„ JQuery๋กœ ๋ณด๋‹ค ์งง๊ณ  ์ง๊ด€์ ์œผ๋กœ ์“ธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
$ ๊ธฐํ˜ธ๋Š” ์ œ์ด์ฟผ๋ฆฌ๋ฅผ ์˜๋ฏธํ•˜๊ณ , ์ œ์ด์ฟผ๋ฆฌ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ์‹๋ณ„์ž์ž…๋‹ˆ๋‹ค. ์„ ํƒ์ž๋ฅผ ์ด์šฉํ•˜์—ฌ ์›ํ•˜๋Š” HTML ์š”์†Œ๋ฅผ ์„ ํƒํ•˜๊ณ , ๋™์ž‘ ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•˜์—ฌ ์„ ํƒ๋œ ์š”์†Œ์— ์›ํ•˜๋Š” ๋™์ž‘์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

โœ๏ธ jquery ํ™œ์šฉ ์˜ˆ์‹œ

๐Ÿ’ก $(์„ ํƒ์ž).๋™์ž‘ํ•จ์ˆ˜();

)//Javascript
document.querySelector(".slider").innerHTML = "image";

//Jquery
$(".slider").html("image");

#2. jquery ์‚ฌ์šฉ ๋ฐฉ๋ฒ•

๐Ÿ“– CDN ์นดํ”ผํ•˜๊ธฐ ๐Ÿ“–

jquery์‚ฌ์ดํŠธ์— ๋“ค์–ด๊ฐ€์„œ ๋‹ค์šด๋กœ๋“œ ์ œ์ด์ฟผ๋ฆฌ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
์Šคํฌ๋กค์„ ๋‚ด๋ฆฌ๋‹ค ๋ณด๋ฉด ์•„๋ž˜ ์‚ฌ์ง„๊ณผ ๊ฐ™์ด CDN ์นดํ”ผ ์„น์…˜์ด ๋‚˜์˜ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๊ทธ ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•˜์—ฌ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

! GOOGLE CDN ์˜ˆ์ œ !
3.x snippet: ๊ฐ€์žฅ ์ตœ๊ทผ ๋ฒ„์ „
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
1.x snippet: ์ต์Šคํ”Œ๋กœ๋Ÿฌ ์ง€์› ๋ฒ„์ „
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

๐Ÿ“– Jquery ๋‹ค์šด๋กœ๋“œ ๐Ÿ“–

์œ„์™€ ๋˜‘๊ฐ™์ด jquery์‚ฌ์ดํŠธ์— ๋“ค์–ด๊ฐ€์„œ ๋‹ค์šด๋กœ๋“œ ์ œ์ด์ฟผ๋ฆฌ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
๋‹ค์šด๋กœ๋“œ ํ›„ ์ œ์ด์ฟผ๋ฆฌ jsํŒŒ์ผ์„ html๊ณผ ๊ฐ™์€ ๊ฒฝ๋กœ์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

! ์ฃผ์˜ !
ํฌ๋กฌ์—์„œ๋Š” ๋”ฐ๋กœ ๋‹ค์šด๋กœ๋“œ ํŒŒ์ผ์„ ์ง€์›ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์ต์Šคํ”Œ๋กœ๋Ÿฌ์—์„œ ๋‹ค์šด์„ ๋ฐ›์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค.


#3. jquery ๊ธฐ๋ณธ ํ˜•์‹

jquery๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ $(document).ready()๋กœ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ready()๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ์ด๋ฒคํŠธ์— ํ•ด๋‹นํ•˜๋ฉฐ ํŠนํžˆ load ์ด๋ฒคํŠธ์™€ ์•„์ฃผ ์œ ์‚ฌํ•œ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ต๋‹ˆ๋‹ค!
๊ทธ๋Ÿผ ๋‹ค์Œ ์˜ˆ์ œ๋ฅผ ํ†ตํ•ด ๊ธฐ๋ณธ ํ˜•์‹์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ด…์‹œ๋‹ค!

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Jquery ๊ธฐ๋ณธํ˜•์‹</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js">//CDN ์นดํ”ผ ๋ฐฉ์‹</script>
    <script>
        $(document).ready(function(){
            ์‹คํ–‰๋ฌธ;
        });
    </script>
</head>
<body>
</body>
</html>

โœ๏ธ jquery ๋ ˆ๋””๋ฅผ ์งง๊ฒŒ ํ‘œํ˜„

$(document).ready()์—์„œ document์™€ .ready๋ฅผ ์ƒ๋žตํ•˜์—ฌ ์งง๊ฒŒ ํ‘œํ˜„ํ•ด์ค๋‹ˆ๋‹ค.

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Jquery ๊ธฐ๋ณธํ˜•์‹</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js">//CDN ์นดํ”ผ ๋ฐฉ์‹</script>
    <script>
        $(function() {
            ์‹คํ–‰๋ฌธ;
        });
    </script>
</head>
<body>
</body>
</html>
728x90

๋Œ“๊ธ€


Lucky Charms Rainbow
js
html
css