-
Notifications
You must be signed in to change notification settings - Fork 0
/
lists
55 lines (43 loc) · 921 Bytes
/
lists
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
<select id="cars">
<option value="benz">Benz</option>
<option value="audi">Audi</option>
<option value="bmw">bmw</option>
</select>
<button id="b1">
click me
</button>
<ol id="here">
</ol>
#cars{
width: 100px;
}
function myfunc()
{
let value=document.getElementById("cars").value;
console.log(value);
if(value=="benz")
{
let obj=benz.display()
console.log(obj);
for(let i in obj){
let node=document.createElement('LI')
let text=document.createTextNode(i+"="+obj[i])
node.appendChild(text)
document.getElementById("here").appendChild(node)
}
}
}
let cars=function(id,name,color){
this.id=id;
this.name=name;
this.color=color;
this.image=""
this.display=function(){
return {id:this.id,name:this.id,color:this.color}
}
}
let benz=new cars(100,"Benz","Red")
let audi=new cars(101,"Audi","Blue")
let bmw=new cars(102,"BMW","Green")
/
document.getElementById("b1").addEventListener("click",myfunc)