记录以下网址的javascript core crash章节[url]http://courses.coreservlets.com/Course-Materials/ajax-basics.html[/url]
[b][size=x-large]1、载入[/size][/b]
[b][size=x-large]2、注释 [/size][/b]
同Java一样,
[b][size=x-large]3、条件语句[/size][/b]
true和false和Java不同
[quote]•[b][color=red] 以下条件被当成“false”[/color] [/b]: false null undefined "" (empty string) 0 NaN false : false, null, undefined, (empty string), 0, NaN
•[b] [color=red] 以下条件被当成“true”[/color][/b]: anything else (including the string "false")[/quote]
[b][size=x-large]4、数组、for循环[/size][/b]
先看结果:
[img]http://dl.iteye.com/upload/attachment/0061/9707/9447c6a8-a862-31be-b2b5-9605a5a42e1c.png[/img]
[b][size=x-large]1、载入[/size][/b]
/*方法1、从外部载入;适合函数定义*/
<script src="my-script.js" type="text/javascript"></script>
/*方法2、直接在html中写出;直接执行!!!*/
<script type="text/javascript">JavaScript code</script>
[b][size=x-large]2、注释 [/size][/b]
同Java一样,
//行注释
/* 块注释 */
[b][size=x-large]3、条件语句[/size][/b]
true和false和Java不同
[quote]•[b][color=red] 以下条件被当成“false”[/color] [/b]: false null undefined "" (empty string) 0 NaN false : false, null, undefined, (empty string), 0, NaN
•[b] [color=red] 以下条件被当成“true”[/color][/b]: anything else (including the string "false")[/quote]
[b][size=x-large]4、数组、for循环[/size][/b]
先看结果:
[img]http://dl.iteye.com/upload/attachment/0061/9707/9447c6a8-a862-31be-b2b5-9605a5a42e1c.png[/img]
<!-- LCTestForLoop.html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
h3{
color: #FFF;
background-color: #09F;
font-style: normal;
font-weight: bold;
}
h4 {
font-weight: bolder;
color: #d00;
background-color: #CCC;
}
</style>
<title>javascript数组及for语句测试</title>
</head>
<body>
<h3>遍历对象的属性,for/in语句; 注意拿出的是下标!!</h3>
<h4>var person = { firstName : "Brendan",lastName : "Eich" };//声明对象</h4>
<script type="text/javascript">
var person = { firstName : "Brendan",lastName : "Eich" };
for ( var property in person) {
document.write("<p>" + person[property]);
}
</script>
<h3>for语句;数组的声明、遍历——数组为:var arrayInt = [ 5, 4, 2,2];</h3>
<h4>常规方法 </h4>
<script type="text/javascript">
var arrayInt = [ 5, 4, 2,2];//一维数组的声明用方括号 ,下标从0开始
for(var ind=0;ind<arrayInt.length;ind++){
document.write("\t"+arrayInt[ind]);
}
</script>
<h4>注意:for/in语句的自变量为下标(不推荐此方法)——数组为:var arrayInt = [ 7, 4];<p> 覆盖了上面的变量;此处不声明将沿用上面的!! </h4>
<script type="text/javascript">
var arrayInt = [ 7, 4];//一维数组的声明用方括号 ,下标从0开始;此处的定义覆盖了上面的
for ( var ind in arrayInt) {//不推荐
document.write("<p>下标:"+ ind);
document.write(";\t\t\t内容:" + arrayInt[ind]);
}
</script>
<h3>动态数组</h3>
<h4>var array = [0];array[4]=8;//动态调整数组</h4>
<script type="text/javascript">
var array = [0];
array[4]=8;//动态调整数组
document.write("数组内容:");
for(var ind=0;ind<array.length;ind++){
document.write("\t"+array[ind]);
}
document.write("<p>array[1]==null?\t"+(array[1]==null));
</script>
</body>
</html>