08 基于对象的JS语言范例

[标签:图片]

JavaScript语言是基于对象的(Object-Based),而不是面向对象的(object-oriented)。之所以说它是一门基于对象的语言,主要是因为它没有提供象抽象、继承、重载等有关面向对象语言的许多功能。而是把其它语言所创建的复杂对象统一起来,从而形成一个非常强大的对象系统。

 

虽然JavaScript语言是一门基于对象的,但它还是具有一些面向对象的基本特征。它可以根据需要创建自己的对象,从而进一步扩大JavaScript的应用范围,增强编写功能强大的Web文文件。

 

三、范例

下面是一个时钟显示的JavaScript文檔。在文文件中用了非常多的函数。

Test4_1.htm


<html>

<head>

<style TYPE="text/css">

<style>

</style>

 

<title>时钟</title>

 

<script LANGUAGE="JavaScript">

function showClock() {


}

function hideClock() {


}

var timerID = null

var timerRunning = false

function stopClock() {

if(timerRunning)


clearTimeout(timerID);

timerRunning = false

 

document.clock.face.value = "";


}

function showTime() {


var now = new Date();

var year = now.getYear();

var month = now.getMonth() + 1;

var date = now.getDate();


var hours = now.getHours();

var mins = now.getMinutes();

var secs = now.getSeconds();

var timeVal = "";

 

timeVal += ((hours <= 12) ? hours : hours - 12);

timeVal += ((mins < 10) ? ":0" : ":") + mins;

 

timeVal += ((secs <= 10) ? ":0" : ":") + secs;


timeVal += ((hours < 12) ? "AM" : "PM");

timeVal += ((month < 10) ? " on 0" : " on ") + month + "-";

timeVal += date + "-" + year;

 

document.clock.face.value = timeVal;

 

timerID = setTimeout("showTime()", 1000);

timerRunning = true

}

 

function startClock() {

stopClock();

 

showTime();


}


function windowOpener( indexnum ){

 

var loadpos="date.html"+"#"+indexnum;


controlWindow=window.open(loadpos,"date","toolbar=no,location=no,directories=no,

status=no,menubar=no,scrollbars=yes,resizable=yes,width=620,height=400");

}

</script>

 

</head>

<body onLoad="startClock()" >

<p align="center"><big><span style="background-color: rgb(45,45,45)"><font face="Arial">form</font> &nbsp; <font face="宋体">时钟</font></span></big></p>

 

<p align="center"></p>

 

<div align="center"><center>

<table border="0" cellspacing="0" cellpadding="0">

<tr>


<td width="100%"><form NAME="clock" onSubmit="0">

<div align="center"><center><p><input TYPE="text" NAME="face" size="20" VALUE style="background-color: rgb(192,192,192)"> </p>

 

</center></div>


</form>

 

</td>

</tr>

</table>

</center></div>

</body>

</html>



本讲介绍了基于对象的JavaScript中常用内部对象属性、方法的使用。

更多精彩内容:对象 语言 面向 文件 功能 强大 

最新评论

发表评论

为“08 基于对象的JS语言范例”说几句吧

评论内容:发表评论不能请不要超过250字;发表评论请自觉遵守互联网相关政策法规。

关于我们 - 供应商加盟 - 人才招聘 - 版权声明 - 网站地图 - 友情链接

Copyright © 2009-2023 yr.pinnace.cn All Rights Reserved. 17育儿网 版权所有

粤ICP备11040004号-1