当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JavaScript教程:基于对象的JS语言范例

Javascript
JS 参数传递的实际应用代码分析
prototype与jquery下Ajax实现的差别
用JS写的简单的计算器实现代码
javascript 数组操作实用技巧
JavaScript 中级笔记 第二章
JavaScript 中级笔记 第三章
JavaScript 中级笔记 第四章 闭包
JavaScript 中级笔记 第五章 面向对象的基础
Mootools 1.2教程 函数
Mootools 1.2教程 事件处理
通过Mootools 1.2来操纵HTML DOM元素
Mootools 1.2教程 设置和获取样式表属性
Mootools 1.2教程 输入过滤第一部分(数字)
Mootools 1.2教程 输入过滤第二部分(字符串)
Mootools 1.2教程 Fx.Tween的使用
Mootools 1.2教程 Fx.Morph、Fx选项和Fx事件
MooTools 1.2中的Drag.Move来实现拖放
Mootools 1.2教程 正则表达式
Mootools 1.2教程 定时器和哈希简介
Mootools 1.2教程 滚动条(Slider)

Javascript 中的 JavaScript教程:基于对象的JS语言范例


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 339 ::
收藏到网摘: n/a

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中常用内部对象属性、方法的使用。