JavaScript对象
JavaScript对象
JavaScript对象是拥有属性和方法的数据。
对象也是一个变量,但对象可以包含多个值(多个变量)。
var car={type:"Fiat",model:500,color:"white"};
案例:
<!DOCTYPE html><html>
<body>
<p id="car1"></p>
<script>
var car={
name:"法拉利",
model:500,
weight:850,
color:"white",
show:function()
{
return this.name+" "+this.model+" "+this.weight+"kg"+" "+this.color;
}
};
document.getElementById("car1").innerHTML=car.show();
</script>
</body>
</html>
结果: