본문 바로가기
HTML│CSS│Java Script

p 태그 id에 자바스크립트 결과 담기

by 자유코딩 2017. 12. 6.

p 태그 id에 자바스크립트 결과 담기

 

코드

 

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
    //객체 생성
    var person=new Object();
    person["name"]="최은서";
    person["age"]="20";
    person["salary"]=3200;
    
    document.write(person["name"]+"<br/>");
    document.write(person.age+"<br/>");
    document.write(person.salary+"<br/>");
</script>
</head>
<body>
    <p id="demo1"></p>
    <p id="demo2"></p>
    <p id="demo3"></p>
    <p id="demo4"></p>
    <script type="text/javascript">
        var car ={
                type:"Fiat",
                model:"500",
                color:"white"
        }
        document.getElementById("demo1").innerHTML=car.model;
    </script>
    <script type="text/javascript">
        function prn(msg){
            document.getElementById("demo4").innerHTML = msg;
        }//우회 처리(더 많이 사용한다)
        var person2={
                name:"이서연",
                age:30,
                salary:4800,
                all:function(){
                    return this.name+" , "+this.age + " , "+this.salary;
                },
                month:function(){
                    this.salary/12;
                     document.getElementById("demo3").innerHTML=this.salary/12;
                },//직접 처리
                month2:function(){
                    var mon=this.salary/12;
                    prn(mon);
                }
        }
        document.getElementById("demo2").innerHTML=person2.all();
        person2.month();
        person2.month2();
    </script>
 
</body>
</html>
cs

 

 

'HTML│CSS│Java Script' 카테고리의 다른 글

html 예제  (0) 2017.12.06
html 예제  (0) 2017.12.06
html 전구 켜고 끄기  (0) 2017.12.06
html 표 추가 삭제  (0) 2017.12.06
html 예제  (0) 2017.12.05

댓글