日期:2014-05-16 浏览次数:20335 次
<!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"> <title>我的第一个javascript练习</title> </head> <body> <!-- 2种加载方式 <script type="text/javascript" src="xxxx"></script> --> <script type="text/javascript"> /*定义变量 */ var x= 3; x = "abc";//这里单引号双引号一样 alert(x); if( "abc" == x){ alert("YES"); }else{ alert("NO"); } //SWITCH 语句 alert("switch 语句练习 "); x = 3; switch(x) { case "adc": alert("abc"); break; case 3: alert(3); break; default: alert("something error!"); break; } //写到网页上。 document.write("<font color = 'red'>while ,do ...while,for 和C语言一样</font>"); document.write("数组:"); var arr = [4,1,6,8]; for(var i = 0;i<arr.length;i++) { document.write(arr[i]); } </script> <h1><font color="red">这是我的第一个练习</font></h1> </body> </html>
<script type="text/javascript"> var arry = [5,1,2,7,4]; //排序 for(var i = 0; i < arry.length;i++){ for(var j = i + 1;j < arry.length;j++){ if(arry[j] < arry[i]){ var tmp = arry[i]; arry[i] = arry[j]; arry[j] = tmp; } } } for(i = 0; i < arry.length;i++){ document.write(" "+arry[i]+" "); } </script>
<script type="text/javascript"> //函数 function show(){ alert("show run"); } function show1(){ for(var x = 0;x < arguments.length;x++) alert(arguments[x]); } show(); show1(1,2,3,4); document.write("is OK!"); //动态函数 //var show = new Function("x","y","var sum = x + y; return sum;"); // alert(show(2,3)); //匿名函数 // var show2 = function(){ // /document.write("func run"); //} //show2(); // window.onload = function(){ // document.write("func run----"); //} window.onload = show;//这里不能写成show() </script>
<script type="text/javascript"> function Person(name,age){ this.name = name; this.age = age; } var p = new Person("jsh",28); alert(p['name'] + p.age); function Per(){ document.write("per create!"); } var p1 = new Per(); p