Files
2024-09-27 02:06:13 +08:00

80 lines
1.4 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>对象 object</title>
</head>
<body>
<script>
// var obj = new Object();
// obj.names = "张三"
// obj.age = "18"
// console.log(obj);
// var obj = new Object({
// names: '张三',
// age: "18"
// });
// var obj = {
// names: '张三',
// age: "18"
// }
// console.log(obj);
var cart = {
price: '25万',
color: 'red',
speed: '7',
opendoor: function() {
console.log("打开车门");
},
start: function () {
console.log("点火");
},
run: function () {
console.log("上路跑");
}
}
cart.opendoor()
cart.start()
cart.run()
// json
// 概念 object + array
// 他是一种描述数据格式和结构的方法,以前用 xml
// 作用:
// 前后端分离后后端把数据构造成json格式给前端前端拿到json渲染页面
var json1 = {
status: 200,
result: [
{
id: 1,
title: '今天天气很好'
},
{
id: 2,
title: '今天天气很好2222'
}
]
}
console.log(json1.result[0].title);
</script>
</body>
</html>