본문 바로가기

(Before)BitSchool

2014/06/11 JavaScript

반응형



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>




반응형