1_javascript基本知识_script标签使用_函数定义和调用
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function aa() {
alert("Hi js!");
}
// 注释1
/* 注释2 */
</script>
<script src="1.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
</head>
<body>
<!-- 执行完函数aa()后什么都不做 -->
<a href="javascript:void(0);" οnclick="aa();">test</a>
<!-- 连续执行多个函数 -->
<input type="button" value="测试" οnclick="aa();bb();cc();"/>
</body>
</html>
<!-- 1_javascript基本知识_script标签使用_函数定义和调用 -->
1.js
function bb(){
alert("Hello bb!");
}
function cc(){
alert("Hello cc!");
}
2_变量声明_数据类型_运算符_控制语句(重讲)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>2</title>
<script>
var q = 33;//全局变量
function aa() {
var i = 3;
//变量名区分大小写
var I = 5;
/*
* 不能使用未经声明的变量
* var i = 3 + ccc;
*/
var v = 1, d = 2;
a = "aaa";//如果没有加var,那么当这句代码执行后,该变量会作为全局变量来处理
var date = new Date();
console.log(i + " " + I);// Firfox FireBug 使用语句
}
function bb() {
console.log(a + " " + q);
}
function testDataType() {
var a;//undefined
var b = null;
var c = true;
var d = "<img src=\"aaa.jpg\"></img>";
var d2 = "<img src='aaa.jpg'></img>";
var e = 3;
var f = 3.14;
var g = -1 / 0;//-Infinity
//Infinity 1/0
var g2 = parseInt("a");
if (g2 != g2) {//NaN是唯一一个跟自己不相等的值
console.log("g2:" + g2);
}
console.log("a:" + a + " , b:" + b + " , c:" + c + " ,g:" + g);
}
function testDataTypeAutoConvert() {
var a = "true";
var b = true;
var c = 1;
if (b == c) {
console.log("true");
} else {
console.log("false");
}
/*
* === 不会发生类型的自动转换
* == 会发生类型的自动转换,自动匹配
* null,undefined,false,0可以转
*/
console.log("undefined == null: " + (undefined == null));
//true
console.log("undefined === null: " + (undefined === null));
//false
}
</script>
</head>
<body>
<input type="button" value="测试1" οnclick="aa();"/>
<br/>
<input type="button" value="测试2" οnclick="bb();"/>
<br/>
<input type="button" value="测试3" οnclick="testDataType();"/>
<br/>
<input type="button" value="测试4" οnclick="testDataTypeAutoConvert();"/>
</body>
</html>
<!-- 2_变量声明_数据类型_运算符_控制语句(重讲) -->
3_数组_函数_函数深化
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script>
function aa() {
var a = new Array();
var b = [];//数组直接量
b[0] = 123;
b[1] = "bb";
b[2] = true;
b[3] = new Date();
b.length = 10;
document.write(b);// 123,bb,true,Thu Sep 26 2013 18:16:31 GMT+0800,,,,,,
}
</script>
</head>
<body>
<input type="button" value="测试1" οnclick="aa();"/>
</body>
</html>
<!-- 3_数组 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script>
function aa(a,b,c){
console.log(a+b+c);
return a * 10;
}
function bb(){ // var bb = function(){}
var v = aa(20,30,40);
console.log(v);
}
var cc = function(){
console.log("函数也是对象!");
}
function dd(){
var r = cc;
r();
}
function ee(s){//函数可作为参数传递
s();
}
var testEval = function(s){
eval(s);
}
function ff(){
var str = "中国";
var str1 = escape(str);//url编码
console.log(str1);
var str2 = unescape(str1);
console.log(str2);
}
</script>
</head>
<body>
<input type="button" value="测试1" οnclick="aa(22,33,44);"/>
<br/>
<input type="button" value="测试2" οnclick="bb();"/>
<br/>
<input type="button" value="测试3" οnclick="cc();"/>
<br/>
<input type="button" value="测试4" οnclick="dd();"/>
<br/>
<input type="button" value="测试5" οnclick="ee(cc);"/>
<br/>
<input type="button" value="测试6" οnclick="testEval('var h=3;alert(h)');"/>
<br/>
<input type="button" value="测试7" οnclick="ff();"/>
<br/>
</body>
</html>
<!-- 3_函数_函数深化 -->