jquery1.html
2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>jQuery Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<style type="text/css">
.section { padding:5px; margin:5px; border:1px solid #eeeeee;}
div#result { border: 1px solid red; background:#EEEEEE;
padding:10px;margin:10px; }
</style>
</head>
<body>
<div class="section">
<ul id="fruits">
<li>Apple</li>
<li>Orange</li>
<li>Melon</li>
</ul>
</div>
<div class="section">
<a href="http://www.google.com">Google</a>
<a href="http://www.apple.com">Apple</a>
<a href="http://www.microsoft.com">Microsoft</a>
<a href="http://www.oracle.com">Oracle</a>
</div>
<div class="section">
<form id="test">
<input type="text" name="id" id="id"><br>
<input type="password" name="pwd" id="pwd"><br>
<select id="channel" name="channel">
<option value="kbs">KBS</option>
<option value="mbc">MBC</option>
<option value="sbs">SBS</option>
</select>
<p>
<input type="checkbox" name="hobby" value="baseball">야구
<input type="checkbox" name="hobby" value="basketball">농구
<input type="checkbox" name="hobby" value="soccer">축구
</p>
<p>
<input type="button" id="btn1" value="버튼1">
<input type="button" id="btn2" value="버튼2">
<input type="button" id="btn3" value="버튼3">
</p>
</form>
</div>
<div id="result">
<h3>RESULT</h3>
</div>
</body>
</html>
<script type="text/javascript">
$(function() {
// text / html 읽기
$("#result").append($("#fruits").html() + "<p>");
$("#result").append($("#fruits").text() + "<p>");
// value 읽기
$("#result").append($("#channel").val() + "<p>");
// CSS 읽기
$("#result").append($("a:last").css("margin-top") + "<p>");
// Attribute 읽기
$("a").each(function(idx) {
$("#result").append("a" + idx + ":" + $(this).attr("href")+ "<br>");
});
// value 설정
$("#id").val("아이디");
$("#pwd").val("123");
// Attribute 설정
$("input[type='checkbox']").filter("[value='soccer']")
.attr('checked', 'checked');
// text 설정
$("#fruits").find("li:first").text("사과");
// click event + effect
$("#btn1").val("toggle").click(function() {
$("div.section:first").toggle();
});
$("#btn2").val("slide up").click(function() {
$("div.section:first").slideUp();
});
$("#btn3").val("slide down").click(function() {
$("div.section:first").slideDown();
});
// mouse event
$("div.section").mouseover(function() {
$(this).css("background", "#f8dff5");
});
$("div.section").mouseout(function() {
$(this).css("background", "#ffffff");
});
// change event
$("#channel").change(function() {
alert("You selected '" + $(this).val() + "'");
});
});
</script>