script language javascript script head body head body
§ 내부 자바스크립트 <script language = "javascript" > ㆍ ㆍ ㆍ </script> ◦ <head> 태그 내 또는 <body> 태그 내에 내장 <head> 태그 내 는 주로 정의 <body> 태그 내는 실행 § 사용 예 <html> <head><title> script 태그 넣기 </title></head> <body> <script language = "Java. Script"> document. write("여기는 body 태그 내 자바스크립트") </script > </body></html>
Html 문서와 스크립트 사용 문서 비교 § 일반적인 HTML 문서에서의 메시지 표현 <html> <head><title>document 개체에 태그 접목 </title></head> <body> <font color="red" size="5">여러분 안녕하세요. </font> <hr color="red"> 열심히 연습하세요 <img src="house. gif"> <a href = "http: //www. daum. net"> 다음사이트</a> </body></html> § 자바스크립트 내에서의 메시지 표현 <html><head><title>document 개체에 태그 접목 </title></head> <body> <script language="javascript"> document. write("<font color='red' size=' 5' >") document. write("여러분 안녕하세요. " + "</font> ") document. write("<hr color='red'>") document. write("열심히 연습하세요 ") document. write("<img src="house. gif"> ") document. write('<a href = "http: //www. daum. net">') document. write(" 다음사이트"+"</a>") </script> </body> </html>
§ if 문 사용 예 <html> <head><title>if문</title></head> <body> <b>if 문 연습</b> <hr color="gray"> <script language="javascript"> busy = "바쁨" document. write("<b>당신은" + busy + "니까? ") if (busy == "바쁨") document. write(busy + "지하철을 타세요</b>") if (busy =="안 바쁨") document. write(busy + "버스를 타세요</b>") </script> </body></html>
§ for 문 사용 예 <html> <head><title>for 문 연습</title></head> <body> <script language="Java. Script"> for (i=1; i<=7; i++){ if(i%2==1) document. write("<font size=", i, ">어서오세요. </font> ") else document. write("<font color=red size=", i, "> 어서오세요. </font> ") } </script> </body></html>
§ while 문 사용 예 <html> <head><title>while 문</title></head> <body><b>while 문 연습</b> <hr color="red"> <script language="javascript"> x=0; total=0 While (x < 10) { x++; total = total + x; document. write("<b>"+ x); if(x != 10) document. write("<b> + ") } document. write("<b> = " + total) </script> </body></html>
§ 매개변수만 있고 리턴 값이 없는 경우 사용 예 <html> <head><title>사용자 정의 함수</title> <script language="Java. Script"> function add(a, b) { var c c=a+b document. write(c) } </script></head> <body><b> function 문 연습 <hr> <script language="Java. Script"> x = 13; y = 14; document. write(x + " + y + " = ") add(x, y) </script> </body></html>
§ 매개변수도 있고 리턴 값도 있는 경우 사용 예 <html><head><title>함수 정의와 호출</title> <script language="Java. Script"> function Get. Sum(y) { total = 0; for (var count = 1; count <= y; count++) total += count ; return total; } </script></head> <body> <script language="Java. Script"> x=100 document. write("<h 3>함수 정의와 호출</h 3><hr>") document. write("1부터"+ x +"까지의 합은: ", Get. Sum(x)) </script> </body></html>
- Slides: 20