160517: 44회차
종료하기 전 티스토리 네이버 로그아웃 할 것
1. 툴
동일
추가시:
2. 폴더
동일
추가시:
3. 사용할 사이트
동일
추가시:
4. 공부하는 것
Web Publishing
-webpub
Ajax 시작
http://www.lectureblue.pe.kr/reqtiles/read.jsp?bbsno=215&nowPage=1&col=&word=&code=14
D:\javadb\ojt 만들었음 :>
그리고 나서
\workspace 만든담에
encoding / web browser / server runtime environment 잡아줬음
- HTML을 조작하기위한 자바스크립트 함수들의 집합을 모델화하여 만든것을 DOM이라고 합니다.
- Ajax로 어플리케이션 서버로부터의 응답 결과를 전송받아 브러우저의 HTML상에 출력할 때에 DOM 모델을 이용합니다.
- Web Page가 로딩될때 브라우저는 그페이지의 Document Object Model를 생성합니다.
- HTML DOM은 동적으로 HTML 태그를 생성할때 필요합니다.
Ajax - 비동기통신
동기 - 요청하면 데이터처리를 받고 새롭게 결과를 뿌려주는 것
비동기 - 이미 페이지는 뿌려져 있는데 한 부분만 계속 바뀌는 것
(이미 요청이 된 상태지만 바뀐 부분만 응답해서 바꾸는 것)


html을 finding하는 dom 모델인것 ㅋㅋㅋㅋ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form id = "frm1" action = "form_action.asp">
First name: <input type = "text" name = "fname" value = "Donald"><br>
Last name: <input type = "text" name = "lname" value = "Duck"><br><br>
<input type = "submit" value = "전송">
</form>
<p>Click "Try it" to display the value of each element in the form.</p>
<button onclick = "myFunction()">Try it</button>
<p id = "demo"></p>
<script>
function myFunction(){
var x = document.forms["frm1"];
var text = "";
var i;
for(i = 0; i < x.length; i++){
text += x.elements[i].value + "<br>";
}
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
</html>
//form의 하위요소들을 참조할 수도 있음
text += x.elements[i].value + "<br>";
x[i]해도 되지만 x.elements라고 써서 하나하나 하위 요소를 참조하는 것
-----------------------------------------------------------
element.attribute랑 element.setAttribute(attribute, value)랑 같은 것
--------------------------------------------------------------
[02] HTML DOM 실습 1
아직 하고 있음
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script>
window.onload = function(){
var divel = document.getElementById("divHolder");
alert("divHolder div의 자식노드의 개수는: " + divel.childNodes.length);
}
</script>
</head>
<body>
<div id = "divHolder">
<!-- Ajax 정복 루트-->
<div>HTML</div>
<div>JavaScript</div>
<div>DOM</div>
<div>Ajax</div>
</div>
</body>
</html>
이거 하고 있음
이거는 열고 닫고 ./ 텍스트값 이런 것까지 다 포함인데
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
// 페이지가 로딩되면 자동 실행
window.onload = function(){
var count =0;
var divel = document.getElementById('divHolder');
// 자식 노드 수 만큼 순환
for (i=0; i < divel.childNodes.length ; i++){
if (divel.childNodes[i].nodeType == 1){ // 태그인지 검사
count++; // 태그의 갯수 증가
}
}
alert ("자식 엘레멘트(태그) 노드의 갯수는 " + count);
}
</script>
</head>
<body>
<div id="divHolder">
<!-- Ajax 정복 루트 -->
<div>HTML</div>
<div>JavaScript</div>
<div>DOM</div>
<div>Ajax</div>
</div>
</body>
</html>
이렇게 divel.childNodes[i].nodeType == 1 이것만 검사해주면 자식 개수만 가져올 수 있음.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
window.onload = function(){
// ⓐ innerText는 div 태그의 값을 가져옵니다.
var div1text = document.all.div1.innerText;
//비표준임! - id랑 class 속성을 다 찾아봄.
// ⓑ firstChild.nodeValue는 div2 태그의 값을 가져옵니다.
var div2el = document.getElementById('div2');
var div2text = div2el.firstChild.nodeValue;
//firstChild(처음 보이는 것 중에서).nodeValue(데이터값 - 이너텍스트랑 비슷한 것)
//이게 표준임!
// ⓒ 모든 브러우저를 호환함
// document.getElementById('div3').textContent 조건문은 FireFox인지 검사
// FireFox는 textContent 속성으로 DIV 태그의 내용을 가져옵니다.
var div3text = (document.getElementById('div3').textContent)? document.getElementById('div3').textContent : document.getElementById('div3').innerText ;
//이 브라우저가 인식하는 형태가 무엇인지에 따라서
//텍스트 형태 인식 - 그대로
//innertext로 인식 - innertext로 인식
//표...준...
// 경고창
alert ("div1text :" + div1text +"\r\n" + "div2text :" + div2text +"\r\n" +
"div3text :" + div3text );
}
</script>
</head>
<body>
<div id='div1'>백두산</div><br>
<div id='div2'>한라산</div><br>
<div id='div3'>금강산</div><br>
<div id='div4'>설악산</div><br>
<div id='div5'>관악산</div><br>
</body>
</html>
근데 파이어폭스에서도 다 동작함 ㅋㅋㅋㅋㅋ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function setDiv() {
var str = "<table><tr bgcolor='#00ff00'>";
str = str
+ "<td width='500' height='200' align='center' valign='middle'>";
str = str + "<font color='#ff0000' size='5'>";
str = str + "A0001 - 컴퓨터 A<br>";
str = str + "A0002 - 컴퓨터 B<br>";
str = str + "A0003 - 컴퓨터 C<br>";
str = str + "A0004 - 컴퓨터 D<br>";
str = str + "</font>";
str = str + "</td></tr></table>";
document.getElementById("div1").innerHTML = str;
}
</script>
<script>
function delDiv(){
document.getElementById("div1").innerHTML = "*****";
}
</script>
</head>
<body>
<div id='div1'>*****</div>
<br>
<input type="button" onclick="setDiv()" value="테이블 생성">
<input type="button" onclick="delDiv()" value="테이블 삭제">
</body>
</html>
------------------------------------------
------------------------------------------------
HTML DOM을 이용한 스타일 및 CSS 변경
HTML 스타일 변경하기
자바스크립트에서 HTML 엘리먼트의 스타일을 동적으로 변경할 수 있다. 문법은 다음과 같다.
document.getElementById(id).style.property= "새 스타일" ; |
다음 예제를 보자.
document.getElementById( 'image1' ).style.visibility= "hidden" ; document.getElementById( "p1" ).style.color= "green" ; |
HTML CSS 클래스 변경하기
동적으로 엘리먼트의 class를 설정하면 엘리먼트에 적용된 스타일을 극적으로 변경할 수 있다.
자바스크립트에서는 HTML 엘리먼트의 className 프로퍼티를 동적으로 변경할 수 있다. 문법은 다음과 같다.
document.getElementById(id).className= "새 CSS" ; |
다음 예제를 보자.
document.getElementById( 'image1' ).className= "new-css-1, new-css-2" ; document.getElementById( "p1" ).className= "new-css-3, new-css-4" ; |
스타일시트 활성화와 비활성화
자바스크립트에서는 <link>와 <style> 엘리먼트의 disabled 프로퍼티를 이용해 스타일시트를 활성화하거나 비활성화할 수 있다. disabled 프로퍼티가 true이면 <link>나 <style> 엘리먼트와 관련된 스타일시트가 비활성화되어 브라우저에서 무시하게 된다. 다음 예제를 보자.
<!DOCTYPE html> < html > < head > < title >JavaScript</ title > < link rel = "stylesheet" type = "text/css" href = "ss1.css" id = "ss1" > < link rel = "alternate stylesheet" type = "text/css" href = "ss2.css" id = "ss2" > < style id = "ss3" title = "Sans Serif" > body { font-family: sans-serif; } </ style > </ head > < body > < script type = "text/javascript" > document.getElementById('ss1').disabled = true; document.getElementById('ss3').disabled = true; </ script > </ body > </ html > |
관련 수업
출처: http://codingnuri.com/javascript-tutorial/changing-style-and-css-using-html-dom.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script>
function show(){
document.getElementById("content").style.display = "";
}
function hide(){
document.getElementById("content").style.display = "none";
}
</script>
</head>
<body>
<div id = "content">
DIV 태그 출력<br>
<img src='http://www.apache.org/images/ac2008us_343x114.jpg' width='300' height='250'>
</div>
<input type = "button" onclick ="show()" value="div 보이기">
<input type = "button" onclick = "hide()" value="div 감추기">
</body>
</html>
-------------------------------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function kma(){
document.getElementById("thelink").href="http://www.kma.go.kr";
}
function yahoo(){
document.getElementById("thelink").href="http://www.yahoo.com";
}
function func(){
document.getElementById("thelink").href="javascript:display();";
}
function display(){
alert('display 함수가 호출 되었습니다.');
}
</script>
</head>
<body>
<a id="thelink">클릭하세요</a>
<input type="button" onclick="kma()" value="기상청" />
<input type="button" onclick="yahoo()" value="야후" />
<input type="button" onclick="func()" value="링크로 함수 걸기" />
</body>
</html>
-----------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function show(){
var parentdiv = document.getElementById("textHolder");
var divel = document.createElement("div");
divel.appendChild(document.createTextNode("CBD Developer 8"));
parentdiv.appendChild(divel);
}
function del(){
var parent = document.getElementById("textHolder");
var child = parent.lastChild;
parent.removeChild(child);
}
</script>
<body>
<input type = "button" onclick="show()" value="텍스트 추가">
<input type = "button" onclick="del()" value="텍스트 삭제">
<div id = "textHolder"></div>
</body>
</html>
-----------------------------------------------
남의 코드 가져온 것
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
var i = 1;
function append(){
//div태그검색
i = i + 1;
var parentdiv = document.getElementById("fileHolder");
//새로운 div태그 생성
//텍스트를 담을 div를 하나 만든거다.
var divel = document.createElement("div");
var ffile = document.createElement('input');
ffile.type="file";
//새로운 div태그에 텍스트 생성
//위에섬나든 div에 텍스트노트라는것을 통해서 텍스트를 생성해준다.
divel.appendChild(document.createTextNode("파일 선택 " + i + ": "));
divel.appendChild(ffile);
//새로운 div태그를 부모 div태그인 'textHolder'에 추가
//위에서 새롭게 생성한 div를 추가한다.
parentdiv.appendChild(divel);
}
function del(){
if(i!=1) i = i - 1;
var parentdiv = document.getElementById("fileHolder");
var lastChild = parentdiv.lastChild;
parentdiv.removeChild(lastChild);
}
</script>
<body>
<input type="button" name="btnAdd" onclick="append()" value="파일 선택 추가" />
<input type="button" name="btnAdd" onclick="del()" value="파일 선택 제거" />
<br/>
<div>
파일 선택 1: <input type="file" name="file"/>
</DIV>
<DIV id="fileHolder"></DIV>
</body>
</html>
------------------------
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Insert title here</title> | |
<script> | |
var i = 0; | |
function addf() { | |
var parentdiv = document.getElementById("file"); | |
var divel = document.createElement("DIV"); | |
var file = document.createElement('input'); | |
i++; | |
divel.appendChild(document.createTextNode("파일 선택 " + i)); | |
file.type = "file"; | |
file.name = "file" | |
parentdiv.appendChild(divel); | |
parentdiv.appendChild(file); | |
} | |
function del() { | |
var parentdiv = document.getElementById("file"); | |
var lastChild = parentdiv.lastChild; | |
i--; | |
if(i <= 1) { | |
i = 1; | |
} | |
parentdiv.removeChild(lastChild); | |
parentdiv = document.getElementById("file"); | |
lastChild = parentdiv.lastChild; | |
parentdiv.removeChild(lastChild); | |
} | |
</script> | |
</head> | |
<body> | |
<input type="button" onclick="addf()" value="파일 선택 추가" /> | |
<input type="button" onclick="del()" value="파일 선택 제거" /> | |
<br/> | |
<div id = "file"> | |
</div> | |
</body> | |
</html> |
5. 수업
진도:
hw:
6. 할것
문제집 풀 것 ...
12일 ㅠㅠ
http://cafe.naver.com/ukulelehappy/159087
ajax의 css 공부할 것
'Programming' 카테고리의 다른 글
160519: 46회차 (0) | 2016.05.19 |
---|---|
160518: 45회차 (0) | 2016.05.18 |
160516: 43회차 (0) | 2016.05.16 |
160513: 42회차 (0) | 2016.05.13 |
160512: 41회차 (0) | 2016.05.12 |