1

基本语法


一.引入方式(将<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";

悠悠我心
7 声望1 粉丝