Node(Element)๋ฅผ ๊ฐํธํ๊ฒ ์ปจํธ๋กคํ๊ธฐ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค.
์ฝ๋ ๋ณด๊ธฐ, ๋ฌธ์ ๊ฐ์ฒด ๋ชจ๋ธ ์ฐพ๊ธฐ, ์ ๋๋ฉ์ด์
๋ง๋ค๊ธฐ, ์ด๋ฒคํธ ์ ์ด, Ajax ๊ฐ๋ฐ์ ์ฝ๊ฒ ํ ์ ์๋๋ก ๋์์ธ๋์๋ค.
์๋ฐ์คํฌ๋ฆฝํธ๋ ๊ฐ๋ฅํ์ง๋ง jQuery๊ฐ ๋ ์์ํ๋ค.
jQuery ์ ๋ ํฐ๋ CSS์ ๋์ผํ๋ค
<h1>Where do you want to go?</h1>
<h2>Travle Destinations</h2>
<p>Plan your next adventure</p>
<ul id='destinations'>
<li>Rome</li>
<li>Paris</li>
<li class='promo'>Rio</li>
</ul>
// id๊ฐ destinations ์ธ ์์
$("#destinations");
// class๊ฐ promo ์ธ ์์
$(".promo");
// id๊ฐ destinations ํ์์ li ์์, ์คํ์ด์ค๋ก ํ์(๋ถ๋ชจ์ ์์) ์์ ๊ตฌ๋ถ
$("#destinations li");
// ul ํ์์ li ์์๋ฅผ ์ฐพ์๋ณธ๋ค.
// ์์ ์์ ์กด์ฌํ๋๊ฑฐ ์์ผ๋ฉด ๋ชจ๋ ๊ฐ์ ธ์จ๋ค.
$("#destinations li");
// ul ๋ฐ๋ก ํ์์ li ์์๋ฅผ ์ฐพ์์จ๋ค.
// > ์ง์ ์์ ์์๋ง ๊ฒ์
$("#destinations > li");
// ๋ค์ค ์์ ์
๋ ํ
// , ์ฌ๋ฌ ๊ฐ์ ์์๋ฅผ ๋์์ ๊ฒ์
$(".promo, #france");
// : Filter ์ญํ
// ์ฒซ ๋ฒ์งธ ์์
$("#destinations li:first");
// ๋ง์ง๋ง ์์
$("#destinations li:last");
// ํ์ ๋ฒ์งธ
$("#destinations li:odd");
// ์ง์ ๋ฒ์งธ
$("#destinations li:even");
ํ์์์ ํ์๋ณด๋ค ์๋ฑํ ๋น ๋ฅด๊ฒ ์์๋ฅผ ์ฐพ์ ์ ์๋ค.
<h1>Where do you want to go?</h1>
<h2>Travle Destinations</h2>
<p>Plan your next adventure</p>
<ul id='destinations'>
<li>Rome</li>
<li>Paris</li>
<li class='promo'>Rio</li>
</ul>
// destinations : selection
// find : traversal
$("#destinations").find("li");
// ์ฒซ ๋ฒ์งธ ์์ ์ ํ
$("li").first(); // rome
// ๋ง์ง๋ง ์์ ์ ํ
$("li").last();
// ๋ค์ ์์
$("li").first().next(); // Paris
// ์ด์ ์์
$("li").first().next().prev(); // rome
// ํ์์์ ์์๋ก ํ์
// ๋ถ๋ชจ ์์ ์ ํ, ์ฌ๋ฌ ๋ฒ ์ฐ๊ฒฐํ์ฌ ์ฌ์ฉ ๊ฐ๋ฅ(์ฒด์ด๋)
$("li").first().parent();
// ์์ ์์ ์ ํ
$("#destinations").children("li");
// jQuery ์ฌ์ฉํ๋ ค๋ฉด ํ์
// $(document).ready(){}
$(document).ready(function() {
var price = "$("<p>From $399.99</p>");
// before() : ์ ํํ ์์์ ์ด์ ์์น์ ์ ์์ ์ถ๊ฐ
// .vacaton ์์์ ์ด์ ์ price ์์ ์ถ๊ฐ
$(".vacaton").before(price);
// after() : ์ ํํ ์์์ ๋ค์ ์์น์ ์ ์์ ์ถ๊ฐ
// .vacaton ์์์ ์ดํ์ price ์์๋ฅผ ์ถ๊ฐ
$(".vacaton").after(price);
// prepend() : ์ ํํ ์์์ ๋งจ ์ ์์น์ ์ ์์ ์ถ๊ฐ
// .vacation ์์์ ์์ชฝ ๊ฐ์ฅ ์ฒซ ๋ถ๋ถ์ ์์๋ฅผ ์ถ๊ฐ
$(".vacaton").prepend(price);
// apend() : ์ ํํ ์์์ ๋ง์ง๋ง ์์น์ ์ ์์ ์ถ๊ฐ
// .vacaton ์์์ ์์ชฝ ๊ฐ์ฅ ๋ง์ง๋ง ๋ถ๋ถ์ ์์๋ฅผ ์ถ๊ฐ
$(".vacaton").apend(price);
// remove() : ์ ํํ ์์ ์ญ์
$(".button").remove();
});
๋ฒํผ์ ํด๋ฆญํ๋ฉด ํด๋ฆญํ ๋ฒํผ๋ง ์ญ์ ํ๊ณ ๊ทธ ์๋ฆฌ์ p ์๋ฆฌ๋จผํธ๊ฐ ์ถ๊ฐ๋๋ฉฐ ๊ธ์ก์ ๋ณด์ฌ์ฃผ๋ ์์
$(document).ready(function() {
$("button").on("click", function() {
var price = "$("<p>From $399.99</p>");
// ํด๋ฆญํ์ง ์์ ๋ฒํผ ์์ญ์๋ p ์๋ฆฌ๋จผํธ๊ฐ ์ถ๊ฐ๋๋ ๋ฌธ์ ๊ฐ ๋จ์ ์๋ค.
$(".vacation").append(price);
// ๋ฒํผ์ด div ์๋๋ก ์ด๋ํ๋ค๋ฉด p ์๋ฆฌ๋จผํธ๋ div ์์ชฝ์ผ๋ก ์ถ๊ฐ๋๋ค.
$(this).after(price);
$(this).parent().parent().append(price);
$(this).parent(".vacation").append(price);
// p ์๋ฆฌ๋จผํธ๋ฅผ li ์์ ์ถ๊ฐ
$(this).closet(".vacation").append(price);
$("button").remove(); // ๋ชจ๋ ๋ฒํผ์ด ์ญ์ ๋จ
// ํด๋ฆญํ ๋ฒํผ ์์๋ง ๊ฐ์ ธ์์ ์ญ์
$(this).remove();
});
});
3๊ฐ์ ๋ฒํผ์ด ์์ ๊ฒฝ์ฐ ํด๋ฆญ ์ด๋ฒคํธ ์์
// ๊ธฐ๋ณธ ์์ฑ ์ด์ธ์ ๋ค๋ฅธ ์์ฑ์ ์ถ๊ฐํ๊ณ ์ถ์๋
// data-key="valeu" ํ์์ผ๋ก ์ฌ์ฉ
<li class="vacation onsale" data-price="399.99">
<h3>Hawaiian Vacation</h3>
<button>Get Price</button>
<ul class="comments">
<li>Amazing deal!</li>
<li>Want to go!</li>
</ul>
</li>
$(document).ready(function() {
$("button").on("click", function() {
var amount = $(this).closest('.vacation').data('price');
var price = "$("<p>From $" + amount + "</p>");
$(this).closet(".vacation").append(price);
$(this).remove();
// $(this).closet(".vacation")๊ฐ ๋ฐ๋ณต๋๊ณ ์๋ค
// ๋ณ์์ ํ ๋นํด์ ์ฌ์ฉํ๊ธฐ
var vacation = $(this).closet(".vacation");
var amount = vacation.data('price');
var price = "$("<p>From $" + amount + "</p>");
vacation.append(price);
$(this).remove();
});
});
๋ง์ฐ์ค ์ด๋ฒคํธ ์์
click(), dblclick(), mouseout(), mouseover() ... ๋ฑ๋ฑ
$(document).ready(function() {
// ํด๋ฆญํ์๋
$('.confirmation').on('click', 'button', function(){
$(this).closest('.confirmation').find('.ticket').slideDown();
});
// ๋ง์ฐ์ค ์ฌ๋ฆด๋
$('.confirmation').ons('mouseenter','h3', function(){
$(this).closest('.confirmation').find('.ticket').slideDown();
});
});
ํค๋ณด๋ ์ด๋ฒคํธ ์์
keypress() : ํค๋ณด๋ ๋๋ฅผ๋(๋ฌธ์ ํค ์ ์ธํ ํค ์ฝ๋)
keydown() : ํค๋ณด๋ ๋๋ฅผ๋(๋ชจํผ ํค ์ฝ๋)
keyup() : ํค๋ณด๋์์ ์์ ๋ผ์์ ๋
<div class="vacation" data-price="399.99">
<h3>Hawaiian Vacation</h3>
<p>$399.99 per ticket<p>
<p>
Tickets:
// class ๊ฐ quantity ์ธ ๊ฐ์ด ๋ณ๊ฒฝ๋๋ค๋ฉด
<input type='number' class='quantity' value='1'/>
</p>
</div>
// 399.99 ๋ถ๋ถ์ด ๋ณ๊ฒฝ
<p>Total Price : $<span id='total'>399.99</span></p>
$(document).ready(function(){
$('.vacation').on('keyup','.quantity', function(){
var price = +$(this).closet('.vacation').data('price');
var quantity = +$(this).val();
$('#total').text(price * quantity);
});
});
์ ํํ ์์์ ๊ฐ์ ๊ฐ์ ธ์ค๊ฑฐ๋, ์๋ก์ด ๊ฐ์ ์ ์ฉํ๋ค.
<label for="email">์ด๋ฉ์ผ</label>
<hr/>
<input type="text" id="email" placeholder="Email์ ์
๋ ฅํ์ธ์."/><br/>
<br/>
// Email input์ ์
๋ ฅ๋ ๊ฐ์ ๊ฐ์ ธ์ด
var email = $("#email").val();
// Email input์ ๊ฐ์ ์ธํ
ํ๋ค.
// ์
๋ ฅ ๊ฐ ์ด๊ธฐํ์ ์ ์ฉ
$("#email").val("Email ์
๋๋ค.");

$("#email").val("Email ์
๋๋ค.");๋ <input type="text" id="email" placeholder="Email์ ์
๋ ฅํ์ธ์."/>ํ์ ์์ฑํด์ผ ์๋์ฒ๋ผ ์ ์ฉ๋๋ค.

selct์ ์ ํ๋ ๊ฐ์ ๊ฐ์ ธ์ค๊ฑฐ๋, ์ค์ ํ ์ ์๊ณ , ํญ๋ชฉ ๋ณ๊ฒฝ ์ ๋ค์ํ ์์ ์ ํ ์ ์๋ค.
// select์ ์ ํ๋ ๊ฐ์ ๊ฐ์ ธ์จ๋ค.
var weeks= $("#weeks").val();
// select์ ๊ฐ์ ๊ฐ์ ๋ก ์ ํํ๋ค.
$("#jobs").val("2")
// select์ ์ ํ ํญ๋ชฉ์ด ๋ฐ๋์์ ๋, ์ต์
์ text ๊ฐ์ ๊ฐ์ ธ์ ๊ฒฝ๊ณ ์ฐฝ์ผ๋ก ๋ณด์ฌ์ค๋ค.
$("#jobs").on("change", function(){
aler($("#jobs option:selected").text());
});
์ ํํ ์์์ ์ํ ์์ฑ ๊ฐ์ ๊ฐ์ ธ์จ๋ค.
// radio / checkbox ๊ฐ ์ ํ๋ ๊ฐ์๋ฅผ ๊ฐ์ ธ์จ๋ค.
// ์ ํํ๋์ง ์ํ๋์ง ํ๋จ
console.log($("input[type=radio][name=age]:checked").length);
console.log($("input[type=checkbox][name=hobby]:checked").length);
// radio / checkbox๋ฅผ ๊ฐ์ ๋ก ์ ํํ๊ฒ ํ๋ค.
// "๋ชจ๋์ ํ"์์ ์ฌ์ฉํ๋ค.
// eq(1) ์ด๋ผ๋๊ฑด ๋๋ฒ์งธ ์์๋ฅผ ๊ณ ๋ฅธ๊ฒ (0๋ถํฐ ์์)
$("input[type=radio][name=age]").eq(1).prop("checked", true);
$("input[type=checkbox][name=hobby]").eq(1).prop("checked", true);
// ์ฒดํฌ๋ฐ์ค ์ ํํ์ ๋ ์ด๋ฒคํธ ๋ฐ์
// ์ฒดํฌ๋ฐ์ค ํด๋ํ์ ๋, ์ฒดํฌ๊ฐ ๋ ๊ฒฝ์ฐ ๋ชจ๋ ์ฒดํฌ๋ฐ์ค๋ฅผ ์ฒดํฌํ๋ค.
// ๋ฐ๋์ ๊ฒฝ์ฐ ๋ชจ๋ ์ฒดํฌ๋ฐ์ค์ ์ฒดํฌ๋ฅผ ํด์ ํ๋ค.
$("input[type=checkbox][name=hobby]").on("click", function(){
var checked = $(this).prop("checked");
console.log(checked);
if(checked){
$("input[type[checkbox][name=hobby]").prop("checked", false);
}
else{
$("input[type=checkbox][name=hobby]").prop("checked", false);
}
});
์์์ ์์ฑ๊ฐ์ ๊ฐ์ ธ์ค๊ฑฐ๋ ์๋ก์ด ๊ฐ์ผ๋ก ์ง์ ๊ฐ๋ฅํ๋ค
<input type="button" id="done" value="์๋ฃ" />
$("#done").on("click", function(){
// Validation Check
var form = $("#signUpForm");
// attr ์ ์ด์ฉํด์ ์์ฑ์ ์ ์ํ๋ค.
$(form).attr("action", "/doSignUp");
// attr ์ ๊ฐ์ฒด ๋ฆฌํฐ๋ด๋ก ์ ์ํ ์ ๋ ์๋ค.
$(form).attr({
"method":"post"
"enctype" : "multipart/formdata"
});
$(form).submit();
});
// attr์ ์์ฑ์ ์ด๋ฆ์ ์์ฑํ๋ฉด ๊ฐ์ ์ฝ์ด ์ฌ ์ ์๋ค.
var action = $(form).attr("action");
console.log(action);

console ์ฐฝ์ ๋ฌ ๊ฐ
JavaScript์ XML์ ์ด์ฉํ ๋น๋๊ธฐ์ ๋ฐ์ดํฐ ๊ตํ ๊ธฐ๋ฒ์ด๋ค.
์์ฒญ์ ๋ณด๋ด๊ณ ์๋ต์ด ์ฌ ๋๊น์ง ๊ธฐ๋ค๋ฆฐ๋ค.
์์ฒญ์ ๋ณด๋ด๊ณ ์๋ต์ ๊ธฐ๋ค๋ฆฌ๋ ๋์ ๋ค๋ฅธ ์์
์ ํ ์ ์๋ค.
์ฆ, ์๋ก๊ณ ์นจ์ ํ์ง ์๊ณ ๋ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์ค๋ฉด์ ์นํ์ด์ง๋ฅผ ๊ณ์ ์ฌ์ฉํ ์ ์๋ค.
๋ฐ์ดํฐ๋ฅผ ํค์ ๊ฐ์ ์์ผ๋ก ๊ตฌ์ฑํด ํ ์คํธ ํ์์ผ๋ก ์ฃผ๊ณ ๋ฐ๋ ํ์์ด๋ค.
$.ajax({
type:"POST",
url:"semester_code.php"
data:{
semesterDivision : semesterDivision,
campus_id : campus_id,
semester
Ajax๋ ๋น๋๊ธฐ์ ์ผ๋ก ์๋ฒ์ ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ๊ธฐ ์ํ ๊ธฐ์ ๋๋ ๋ฐฉ์์ด๋ค.
์ด Ajax๋ฅผ ํตํด ์๋ฒ์ ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ผ ์๋ ์๊ณ , ์๋ฒ์์ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์ฌ ์๋ ์๋ค.
์ด๋ ์ฃผ๊ณ ๋ฐ๋ ๋ฐ์ดํฐ ํ์ ์ค ํ๋๊ฐ JSON ์ด๋ค.
์ ๋ ํฐ์ ์ข ๋ฅ๊ฐ ๋ค์ํ๊ณ ์ด์ ์ ๋ฐฐ์ด CSS์ ํท๊ฐ๋ฆฌ๋ ๋ถ๋ถ๋ ์์ง๋ง, ๊ตณ์ด ์ธ์ฐ๋ ค ํ๊ธฐ๋ณด๋ค๋ ์์ ๋ ํ๋ก์ ํธ์ฒ๋ผ ์ค์ ๋ก ์ฝ๋ฉ์ ๋ฐ๋ณตํ๋ค ๋ณด๋ฉด ์์ฐ์ค๋ฝ๊ฒ ์ต์ํด์ง ๊ฒ ๊ฐ๋ค.