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

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 371 ::
收藏到网摘: 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中常用内部对象属性、方法的使用。