简单的了解了javascript 的基本代码,感觉和c#中的语句差不多。

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--利用var俩声明变量,仅仅声明变量,而不指定具体类型-->
<title>javascript study</title>
<!-- <script src="commonjs.js" type="text/javascript"></script>-->
<script type="text/javascript">
var f1 = function (i1, i2) { return i1 + i2; }//所谓的匿名函数
alert(f1(3, 5));
alert(function (x, y) { return x + y; }(2, 4));//生命匿名函数
</script> <script type="text/javascript">
function person(name,age)//声明的不是类,类似于类
{
this.Name = name;//里面有动态增加的属性
this.Age = age;
this.SayHello = function () { alert(this.Name);}//匿名函数
}
var p = new person("liming", 18);
p.SayHello();
alert(p.Age);
</script>
<script type="text/javascript">//声明函数;注意区别函数和上面类似于类的那种区别
function fun(i1, i2) { return i1 + i2; }
alert(fun(10,12));
</script>
<script type="text/javascript" >//利用数组的地方
var names = new Array();
names[0] = "chenlong";
names[1] = "wangxinyu";
names[2] = "godness";
for (var i = 0; i < names.length; i++)
alert(names[i]);
</script>
<script type="text/javascript">
function GetMax(arr)
{
var max=arr[0];
for(var i=1;i<arr.length;i++)
{
if (max < arr[i]) max = arr[i];
}
return max; }
var arr = new Array();
arr[0] = 1;
arr[1] = 5;
arr[2] = 9;
arr[3] = 4;
arr[4] = 12;
arr[5] = 8;
arr[6] = 7;
alert(GetMax(arr));
</script>
<script type="text/javascript">
//练习反转字符串和连接字符串
function myreverse(arr)//此处形参属于引用类型,更改后将要影响最后的原数组
{
for(var i=0;i<arr.length/2;i++)
{
var temp = arr[i];
arr[i] = arr[arr.length - i - 1];
arr[arr.length - i - 1] = temp;
}
return arr;
}
function myjoint(arr)
{
var str = arr[0];
for(var i=1;i<arr.length;i++)
{
str += "|" + arr[i];
}
return str;
}
var ar = new Array();
ar[0] = "long"; ar[1] = "chen";
myreverse(ar)
alert(ar);
alert(myjoint(ar));
alert(ar[0]);
</script>
<script type="text/javascript">
var dict = new Array();
dict["ren"] = "人";
dict["man"] = "男人";
alert(dict.ren);
for(var x in dict)//显示的是对象的KEY
{
alert(x);
}
var p1 = new Object();//可以动态增加属性
p1.Name = "tom";
p1.Age = 10;
p1.SayHello = function () { alert("hello"); }
for (var e in p1)//可以将一个类的属性取出来
alert(e);
</script>
</head>
<body>
<input type="button"value="点击"/>
<a href="javascript:alert('用户你好')">点我</a>
<a href="www.baidu.com" onclick="alert('进入百度网站')">百度</a> </body>
</html>
05-11 22:55