一. 引入形式 (将 <script> 标签放到文档最初,</body> 之前)
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
...
<script src="file.js"></script>
</body>
</html>
二. 根本语法
1. 变量
var a,b,c;
2. 字符串
var mood = 'happy'
var mood = "happy"
var mood = 'don\'t ask';
Tip: 单引号或双引号蕴含都能够,若字符串中含有蕴含的引号,需用来本义
3. 数组
var band = Array(4);
var band = Array();
band(1) = "zhang"; -- 数组填充
4. 对象
命名形式:
var lennon = Object();
lennon.name = "John";
lennon.year = "1940";
或
var lennon = {name = "John",year = "1940"};
在此基础上的数组填充:
var band = Array();
band[0] = lennon;
后果:band[0].name = "John";