β» μνμ½λ© μ μλμ "κ°μ²΄ νμ©" κ°μλ₯Ό μκ°νκ³ μμ±ν κΈμ λλ€.
κ°μ²΄ νλ‘νΌν° λ©μλ μ©μ΄ μ 리
κ°μ²΄(Object)
- μ΄λ¦κ³Ό κ°μΌλ‘ ꡬμ±λ μ±μ§(property)μ μ λ ¬λμ§ μμ μ§ν©μ λλ€.
νλ‘νΌν°(property)
- κ°μ²΄μ μμλ λ³μ
λ©μλ(method)
- κ°μ²΄μ μμλ ν¨μ
<script>
function LinkSetColor(color){
var alist = document.querySelectorAll('a');
var i = 0;
while(i < alist.length){
alist[i].style.color = color;
i = i + 1;
}
}
function BodySetColor(color){
document.querySelector('body').style.color = color;
}
function BodySetBackgroundColor(color){
document.querySelector('body').style.backgroundColor = color;
}
function nightDayHandler(self){
var target = document.querySelector('body');
if(self.value === 'night'){
BodySetBackgroundColor('black');
BodySetColor('white');
self.value = 'day';
LinkSetColor('powderblue');
}
else {
BodySetBackgroundColor('white');
BodySetColor('black');
self.value = 'night';
LinkSetColor('blue');
}
}
</script>
μ μ½λμ κ°μ΄ κ°μ²΄λ₯Ό μ¬μ©νκΈ° μ μ ν¨μλ‘ μ€λ³΅μ μ 리ν΄μ£Όλ μμ μ νλ€.
κ°μ²΄ μμ± λ°©λ²
<h2>Create</h2>
<script>
var coworkers = {
"programmer" : "egoing",
"designer" : "leezche"
};
document.write("programmer : "+coworkers.programmer+"<br>");
document.write("designer : "+coworkers.designer+"<br>");
coworkers.bookkeeper = "duru";
document.write("bookkeeper : "+coworkers.bookkeeper+"<br>");
coworkers["data scientist"] = "taeho";
document.write("data scientist : "+coworkers["data scientist"]+"<br>");
</script>
μ΄λ¬ν κ²°κ³Όλ‘ λͺ¨λ κ°μ²΄κ° μμ±λλ κ²μ λ³Ό μ μλ€.
λ°λ³΅λ¬Έ
<h2>Interate</h2>
<script>
for(var key in coworkers){
document.write(key+' : '+coworkers[key]+'<br>');
}
</script>
λ°λ³΅λ¬Έμ μ¬μ©νλ λ²
- for(var key in coworkers)
key
- programmer, designer λ±
coworkers[key]
- egoing, leezche λ±
λ©μλ μμ± λ°©λ²
<script>
coworkers.showAll = function(){
for(var key in this){
document.write(key+' : '+this[key]+'<br>');
}
}
coworkers.showAll();
</script>
λ©μλλ?
- κ°μ²΄μ μμλ ν¨μ
κ°μ²΄ νμ©
- Bodyμ LinksλΌλ κ°μ²΄μ λ΄μ κ²μ΄λ€.
- κ°μ²΄λ νλ‘νΌν°μ νλ‘νΌν°λ₯Ό ꡬλΆν λ μΌνλ₯Ό λΆμ¬μ£Όμ΄μΌ νλ€.
- BodyλΌλ κ°μ²΄ μμ setColorμ setBackgroundColorλΌλ νλ‘νΌν°λ₯Ό λ£μκ³ ,
- LinksλΌλ κ°μ²΄ μμλ setColorλΌλ νλ‘νΌν°λ₯Ό λ£μλ€.
<!doctype html>
<html>
<head>
<title>WEB1 - HTML</title>
<meta charset="utf-8">
<script>
var Links = {
setColor:function(color){
var alist = document.querySelectorAll('a');
var i = 0;
while(i < alist.length){
alist[i].style.color = color;
i = i + 1;
}
}
}
var Body = {
setColor:function(color){
document.querySelector('body').style.color = color;
},
setBackgroundColor:function(color){
document.querySelector('body').style.backgroundColor = color;
}
}
function nightDayHandler(self){
var target = document.querySelector('body');
if(self.value === 'night'){
Body.setBackgroundColor('black');
Body.setColor('white');
self.value = 'day';
Links.setColor('powderblue');
}
else {
Body.setBackgroundColor('white');
Body.setColor('black');
self.value = 'night';
Links.setColor('blue');
}
}
</script>
</head>
<body>
<h1><a href="index.html">WEB</a></h1>
<input id="night_day" type="button" value="night" onclick="
nightDayHandler(this);
">
<div id="grid">
<ol>
<li><a href="1.html">HTML</a></li>
<li><a href="2.html">CSS</a></li>
<li><a href="3.html">JavaScript</a></li>
</ol>
<div id="article">
<h2>HTML</h2>
<p>is the standard markup language for <strong>creating <u>web</u> pages</strong> and web applications.Web browsers receive HTML documents from a web server or from local storage and render them into multimedia web pages. HTML describes the structure of a web page semantically and originally included cues for the appearance of the document.
</p><p style="margin-top:45px;">HTML elements are the building blocks of HTML pages. With HTML constructs, images and other objects, such as interactive forms, may be embedded into the rendered page. It provides a means to create structured documents by denoting structural semantics for text such as headings, paragraphs, lists, links, quotes and other items. HTML elements are delineated by tags, written using angle brackets.
</p>
</body>
</html>
μ μ½λλ₯Ό 보면 μμ μ½λλ³΄λ€ λ μ λ¦¬κ° μ λ λͺ¨μ΅μ΄λ€.
'π€ Language > π¨ JavaScript' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
JS. λΌμ΄λΈλ¬λ¦¬μ νλ μμν¬, UI vs API (0) | 2022.01.09 |
---|---|
JS. νμΌλ‘ μͺΌκ°μ jsμ½λ κ΄λ¦¬ (0) | 2022.01.09 |
JS. ν¨μ (0) | 2022.01.08 |
JS. λ°°μ΄κ³Ό λ°λ³΅λ¬Έ (0) | 2022.01.08 |
JS. 리νν λ§ μ€λ³΅μ κ±° (0) | 2022.01.07 |