JavaScript基本结构
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>JavaScript基本结构</title>
<meta http-equiv="keywords" content="enter,your,keywords,here" />
<meta http-equiv="description" content="A short description of this page." />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="js/hello.js"></script>
<script type="text/javascript">
//alert("Hello JavaScript !");
//document.writeln("Hello JavaScript !");
var num1;
num1=25;
var num2=13;
var Num1=250; //JavaScript区分大小写
//alert(num1+","+num2+","+Num1);
var flag=true;
var height=180.5;
var name="tom";
hobby="game";
var num3;
var num4=null;
var today=new Date();
var nums=new Array(13,25,250);
//alert(hobby);
/*alert(typeof(num1));
alert(typeof(flag));
alert(typeof(height));
alert(typeof(name));
alert(typeof(num3));
alert(typeof(num4));
alert(typeof(today));
alert(typeof(nums)); */
//switch选择结构
var weekday="星期日";
switch(weekday){
case "星期一":
alert("新的一周又开始了,上坟一样的心情!");
break;
case "星期二":
case "星期三":
case "星期四":
alert("好好工作,好好学习");
break;
case "星期五":
alert("明天就放假了");
break;
default:
alert("睡到自然醒!");
break;
}
//定义一个数组
var names=new Array("tom","alice","mike","jone sun");
//alert(names[2]);
//alert(names.length);
names.sort();
names.reverse();
for(var i=0;i<names.length;i++){
document.writeln(names[i]);
}
document.writeln("<br/>");
//foreach循环
for(var i in names){
document.writeln(names[i]);
}
var username=prompt("请输入您的姓名:","");
alert(username);
</script>
</head>
<body>
<p>
This is my XHTML page.
</p>
<input type="button" value="点我" onclick="alert(‘我是被点了才出来的‘)" /><br/>
<a href="javascript:alert(‘嘿嘿‘)">嘿嘿</a>
</body>
</html>
时间: 2024-10-13 12:03:28