function ArrayTool(){}
var ArrayTool = new ArrayTool();
function getMax(arr)
{
var max = arr[0];
for(var i=0;i<arr.length;i++)
{
if(max<arr[i])
max = arr[i];
}
return max;
}
ArrayTool.getMax = getMax;
arraytool.js
<!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">
<script type="text/javascript" src="arraytool.js"></script>
<script type="text/javascript">
var arr = [5,1,4,8,9,3];//要注意定义数组用的是中括号
var a = ArrayTool.getMax(arr);
alert("max=" + a);
function startTime(){
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById("time").innerHTML=h+":"+m+":"+s;
setTimeout('startTime()',500);
}
function checkTime(i){
if(i<10){
i = "0"+i;
}
return i;
}
</script>
<style type="text/css">
.a{
background-color: #FF0000;
}
.z{
background-color: #000099;
}
.z b{
background-color: #66FF00;
}
a:link,a:visited{
color: #33FF00;
text-decoration: none;
}
</style>
<title>网页测试</title>
</head>
<body οnlοad="startTime()">
<div id="time" class="a"></div>
<a href="#" οnclick="alert('haha')">没有点击效果的链接</a>
<div class="z">fhgf<b>hgj</b>jgffdshh</div>
<p>
DSGFD<b>你好</b>HFhgfhgj
</p>
</body>
</html>
扩展类的功能