반응형
HTML 만 사용
JavaScript 사용
P태그이용 자바스크립트 사용
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // JavaScript Code<!DOCTYPE html> <html> <head> <meta charset="EUC-KR"> <title>Insert title here</title> </head> <body> <h1> My First Web Page</h1> <p id="demo"></p> <script type="text/javascript"> document.getElementById("demo").innerHTML=Date(); </script> </body> </html> |
변수앞에 var를 붙이면 전역변수
javascript - random
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 | <!DOCTYPE html> <html> <head> <meta charset="EUC-KR"> <title>Insert title here</title> </head> <body> <p id="demo">??</p> <button onclick="myFunction()">Try it</button> <br><br> <script type="text/javascript"> function myFunction(){ document.getElementById("demo").innerHTML = Math.random(); } document.write(parseInt("10")+"<br />"); document.write(parseInt("10.33")+"<br />"); document.write(parseInt("34 45 66")+"<br />"); document.write(parseInt(" 60 ")+"<br />"); document.write(parseInt("40 years")+"<br />"); document.write(parseInt("He was 40") + "<br />"); document.write("<br />"); document.write(parseInt("10",10)+"<br />"); document.write(parseInt("010")+"<br />"); document.write(parseInt("10",8)+"<br />"); document.write(parseInt("0x10")+ "<br />"); document.write(parseInt("10",16)+"<br />"); </script> </body> </html> |
섭씨를 화씨로 변환하기
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 | <!DOCTYPE html> <html> <head> <meta charset="EUC-KR"> <title>Insert title here</title> <script type="text/javascript"> function convert(degree){ if(degree=="C"){ F=document.getElementById("c").value*9/5+32; document.getElementById("f").value=Math.round(F); }else{ C=(document.getElementById("f").value*32)*5/9; document.getElementById("c").value=Math.round(C); } } </script> </head> <body> <p><b>Insert a number into one of the input fields below:</b> <form> <input id="c" name="c" onkeyup = "convert('C')">degrees Celsius<br/> equals<br> <input id="f" name="f" onkeyup="convert('F')">degrees Fahrenheit </form> <p>Note that the <b>Math.round()</b> method is used, so that the result will be returned as an integer.</p> </body> </html> |
반응형
'(Before)BitSchool' 카테고리의 다른 글
2014/06/13 AJAX - 서버와 통신, JSON (0) | 2014.06.13 |
---|---|
2014/06/12 JavaScript - 기본함수, 사용자 함수, 이벤트 (0) | 2014.06.12 |
2014/06/11 XML - SAX 파서, generic오류, 생성자 자동 만들기, PULL파서 (0) | 2014.06.11 |
2014/06/10 XML - xml파서, DOM 수정, 추가, 삭제, SAX 파서 (0) | 2014.06.10 |
2014/06/03 XML (0) | 2014.06.03 |