首页  ·  知识 ·  前端
JavaScript类和内置对象
佚名  http://www.webjx.com  综合  编辑:dezai  图片来源:网络
lang=EN-US "FONT-SIZE: 12pt; FONT-FAMILY: 'MS Pゴシック'; mso-bidi-font-family: 'MS Pゴシック'; mso-font-kerning: 0pt">javascri
javascript  和 

javascript是基于
象而非面向象的程序设计语言,它不支持承,javascript在面向象方面与Java的严谨相比,得非常随便。 


 


javascript通
过实现包含属性明和方法定的构造方法来声明,并没有专门class 

如:用来声明Oven
的构造方法 

function Oven(color,type,time) 

{this.color=color; 

this.type=type; 

this.time=time; 

this.info=info; 



function info() 

{document.writeln("
:",this.color); 

document.writeln("
:",this.type); 

document.writeln("出厂日期:",this.time); 



Oven类对例: 

oven1=new Oven("
","精巧型","99.1.1"); 

oven2=new Oven("
","典雅型","99.10.1"); 

oven3=new Oven("黄色","
用型","2000.1.1"); 

jscript1.html: 

 

 

 "</SPAN></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: SimSun; mso-bidi-font-family: SimSun; mso-font-kerning: 0pt">欢</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'MS Pゴシック'; mso-bidi-font-family: 'MS Pゴシック'; mso-font-kerning: 0pt">迎</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: SimSun; mso-bidi-font-family: SimSun; mso-font-kerning: 0pt">选购</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 'MS Pゴシック'; mso-bidi-font-family: 'MS Pゴシック'; mso-font-kerning: 0pt">" 

 

function Oven(color,type,time) 

{this.color=color; 

this.type=type; 

this.time=time; 

this.info=info; 



function info() 

{document.writeln("
:",this.color,"
"); 

document.writeln("
:",this.type,"
"); 

document.writeln("出厂日期:",this.time,"
"); 



 

 

 

烤箱商品

 

 


 

 


 

 


 

 

 


javascript可通下列方法方便地建一个象且可随意添加属性: 

var oven1=new Object(); 

oven1.color="c1"; 

oven1.type="t1"; 

oven1.time="t1"; 


javascript的可用
象有: 


anchor 

applet 

button 

checkbox 

Date 

document 

form 

history 

link 

location 

Math 

password 

radioButton 

reset 

selection 

string 

submit 

text 

textArea 

window 


Navigator的
 


navigator 

window 


history 

document 


anchors 

forms 

links 

location 


一:window
 


window
象是 javascript的最高层对象,它包含除了Navigator象外的所有象。 


注:有些方法和属性只有支持javascript1.2的
浏览器才能使用。 


1.属性: 


defaultStatus:
置状行默字符串,只 


status:描述状
行字符串,可写。 


frames:包含窗口中所有FRAME的
象数frames.length可取得FRAME个数。 


frame:一个FRAME
象。 


self:当前窗口。 


parent:父窗口或frameset。 


top:当前窗口的最高
窗口。 


name:窗口的名字。 


innerHeight:
浏览器窗口内部高度。 


innerWidth:
浏览器窗口内部度。 


outerHeight:
出整个浏览器窗口高度。 


outerWidth:
出整个浏览器窗口度。 


locationbar:
示或浏览器地址,如:locationbar=true 


menubar:
示或浏览器菜单栏,如:menubar=false 


personalbar:
示或浏览器指示,如:personalbar=false 


scrollbars:
示或藏窗口滚动条,如:scrollbars=true 


statusbar:
示或浏览器状态栏,如:statusbar=true 


toolbar:
示或浏览器工具,如:toolbar=false 


java:提供
访问JAVA API属性和方法,如:java.lang.Math.random。 


netscape:提供引用netscape.*工具包。 


sun:提供引用sun.*工具包。 


document:窗口中当前所包含的文档
象。 


location:指定当前文档URL的字符串。 


history:与窗口
关联history象。 


2. 方法 


alert("string"):打
一个警告对话框并string信息。 


confirm("string"):打
一个OK和Cancel按对话框并string信息,若用户选择OK返回true,选择Cancel返回false。 


prompt("string"): 打
一个string信息并行文本入域的对话框,对话关闭时返回用户输入的字符串。(窗口1) 


setTimeout:以毫秒
为单一将要生事件时间。(窗口2和3) 


clearTimeout:重置setTimeout所作的
置。 


captureEvent(eventType):
置窗口捕捉指定型的事件。 


releaseEvents(eventType):停止捕捉指定
型事件。 


handleEvent(event):若
置了captureEvent(),指定型的事件将传递给handleEvent()方法。 


focus():使窗口得到
入焦点。 


blur():除去当前窗口中的
入焦点。 


stop():停止当前文件的下
,相当按下“Stop”按 


close():
关闭窗口。 


open(url,name,features,replaceFlag):
找一窗口或打一新窗口。(窗口2) 


url:指定窗口中
示的源,空字符串将打一空白窗口。 


name:是窗口的名字。 


replaceFlag:
值为true,新窗口将取代原窗口在记录中的位置。 


features:
出逗号分隔窗口属性,如:menubar=no。 


features: 


alwaysLowered=yes|no:窗口是否
在其它窗口下面。 


alwaysRaised=yes|no:窗口是否
在其它窗口上方。 


dependent=yes|no:窗口是否依附于父窗口,即父窗口
关闭时它也关闭 


hotkeys=yes|no:是否取消
热键 


location=yes|no:是否
示当前URL。 


menubar=yes|no:是否
示菜单栏 


resizable=yes|no:是否允
窗口大小。 


scrollbars=yes|no:是否
带滚动条。 


status=yes|no:是否
示窗口底部的状态栏 


titlebar=yes|no:是否
标题栏 


toolbar=yes|no:是否
示工具 


z-lock=yes|no:是否固定窗口位置。 


height|innerHeight=象素
:窗口内容区高度。 


width|innerWidth=象素
:窗口内容区度。 


outerHeight=象素
:窗口高度。 


outerWidth=象素
:窗口度。 


screenX=象素
:窗口左框位置。 


screenY=象素
:窗口上框位置。 


3.窗口事件 


onBlur():窗口失去焦点
 


onDragdrop():当文件或快捷方式被拖
到窗口 


onError:当出
javascript错误时 


onFocus():窗口
得焦点 


onLoad():
浏览器装入 


onMove():窗口被移
动时 


onResize():窗口被改
大小 


onUnload():用
开页 


4.窗口
 


例1: promptdemo.html 


 

 

javascript prompt demo 

 

 

 

document.write("

prompt demo

"); 

msg= prompt ("请输入内容:"); 

document.write(msg+"

"); 

document.close(); 

 

 

 


例2: windowDemo.html 


 

function newwindow() 

{ window. open ("../script1.htm","localwindow","toolbar=no,statusbar=no,menubar=no, 


scrollbars=yes,resizable=no,width=200,height=200"); 





window. status ="我只待一会儿!"; 

setTimeout ("erase()",3000); 


function erase() 



window.status=""; 



 

 

 

javascript window Demo 

 

 

是窗口大小使用演示,注意看一下状态栏


 

 

 


例二: windowdemo2.html 


 

function scroll(seed) 

{var msg="
迎来到袁方JAVA讲坛,讲坛网址:www.triworks.com.cn"; 

var out = " "; 

var c = 1; 

if (seed > 100) 

{seed--; 

var cmd="scroll(" + seed + ")"; 

timerTwo=window.setTimeout(cmd,100); 



else 

if (seed <= 100 && seed > 0) 

{for (c=0 ; c < seed ; c++) 

{out+=" "; 



out+=msg; 

seed--; 

var cmd="scroll(" + seed + ")"; 

window.status=out; 

timerTwo=window.setTimeout(cmd,100); 



else 

if (seed <= 0) 

{if (-seed < msg.length) 

{out+=msg.substring(-seed,msg.length); 

seed--; 

var cmd="scroll(" + seed + ")"; 

window.status=out; 

timerTwo=window.setTimeout(cmd,100); 



else 

{window.status=" "; 

timerTwo=window.setTimeout("scroll(100)",7); 







timerONE=window.setTimeout('scroll(100)',50); 

 

 

 

javascript window Demo2 

 

 




 
本文作者:佚名 来源:http://www.webjx.com
CIO之家 www.ciozj.com 微信公众号:imciow

   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读