当前位置: 首页 > 图文教程 > 网络编程 > 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   浏览: 354 ::
收藏到网摘: n/a

  使用浏览器的内部对象系统, 可实现与HTML文档进行交互。它的作用是将相关元素组织包装起来,提供给程序设计人员使用,从而减轻编程人的劳动,提高设计Web页面的能力。

三、范例
例1:下面我们通过一个例子来说明文档对象的综合应用。输出结果见图6-2所示。
Test6_2.htm

<html>
<head>
</HEAD>
<BOdy>
<Form Name="mytable">
请输入数据:
<Input Type="text" Name="text1" Value="">
</Form>
<A name="Link1" href="test31.htm">链接到第一个文本</a><br>
<A name="Link2" href="test32.htm">链接到第二个文本</a><br>
<A name="Link2" href="test33.htm">链接到第三个文本</a><br>
<A href="#Link1">第一锚点</a>
<A href="#Link2">第二锚点</a>
<A Href="#Link3">第三锚点</a>
<BR>
<Script Language="JavaScript">
document.write("文档有"+document.links.length+"个链接"+"<br>");
document.write("文档有"+document.anchors.length+"个锚点"+"<br>");
document.write("文档有"+document.forms.length+"个窗体");
</script>
</body>
</HTML>

 
图6-2

 
例子2:下列程序随机产生每日一语。
test6_3.html

<HTML>
<HEAD>
<script Language="JavaScript">
<!--
tips = new Array(6);
tips[0]="每日一语(1)";
tips[1]="每日一语(2)";
tips[2]="每日一语(3)";
tips[3]="每日一语(4)";
tips[4]="每日一语(5)";
tips[5]="每日一语(6)";
index = Math.floor(Math.random() * tips.length);
document.write("<FONT SIZE=8 COLOR=DARKBLUE>" + tips[index]+"</FONT>");
</Script>
</HEAD>
</BODY>
</HTML>
输出结果见图6-3所示。

 
图6-3

    本讲主要介绍了JavaScript对象系统的使用方法,其中重点介绍了文档对象及使用。