Javascript第一天

引入的三种方法:

       1、javascript代码插入html文档<head>部分的<script>标签中

例:<head>

              <script type=“text/javascript”>

                     //javascript 代码

                     alert(‘hello world’);

              </script>

       </head>

       2、javascript代码存放在一个独立的文件。

       用.js作为文件的扩展名,再利用<script>标签的src属性指向该文件。

例:test.js

alert(‘hello wordld’);

 

test.html

<head>

       <script type=“text/javascript” src=“test.js”></script>

</head>

3、直接把javascript代码插入html文档body部分。

例:<body>

              Document.write(“Hello world!”)

        </body>

语法:

1、          变量:由var运算符加变量名定义

如:

数值变量定义:

var age=25;

字符串变量定义:

var arr=”happy”

布尔类型:

Var married=true  /  false

              命名规则:第一个字符必须是字母,下划线(_)、或美元符号$

              变量名中不能包含空格或标点符号(下划线(_) 和$ 除外);

              变量名区分大小写;

              不能使用保留字、关键字

posted @ 2016-09-01 21:00  蔚201388  阅读(89)  评论(0编辑  收藏  举报