您好,欢迎访问一九零五行业门户网

初学JavaScript第二章_基础知识

javascript的对象都是实例化了的,只可以使用而不能够创建继承于这些对象的新的子类.
window对象为所有对象的parent
window对象的主要属性有:name,length,parent,self,top,status,default status,opener,closed.
window对象的主要方法有:item,alert,blur,close,confirm,open,focus,showmodaldialog.
document对象的常用属性:alinkcolor,anchors,bgcolor,cookie,domain,embeds,
fgcolor,layers,linkcolor,location,title,url,vlinkcolor
anchors属性的使用:
function gonextanchor(where)
{
window.location.hash = where ;
}
数组对象的创建:
function students(name,age)
{
this.name = name ;
this.age = age ;
}
stu1 = new students(thtwin,22) ;
stu = new array(5) ;
stu[0] = thtwin ;
stu[1] = thtwinj2ee ;
........
stu.length //数组的长度
math对象的相关方法使用:
math.abs(arg) ; //求用户设置数的绝对值
math.max(arg1,arg2) ; //返回两个数中的较大值
math.round(arg1) ; //将浮点数舍入成它最近的一个整数>0.5进一,否则丢掉小数位
math.floor(arg1) ; //求的是小于或等于变量的值
math.ceil(arg1) ; //大于或等于变量的值
math.random() ; //产生一个0到1之间的随机数
javascript中的日期对象:
该对象没有属性,但是可以通过一些方法来设置时间.
禁止使用1970年1月1日之前的时间.
thisday = new date();
thisday = new date(month day,year hours:minutes:seconds) ;
thisday.getyear() ;
thisday.getmonth() ;
thisday.getdate() ;//返回一个月份中的日期值.这个方法直接返回一个1以31之间的日期值
thisday.getday() ;
thisday.gettime() ;//返回一个代表当前日期的整数值.(192687456985)
thisday.gethours() ;
thisday.getminutes() ;
thisday.getsecondes() ;
thisday.tolocalestring() ;//返回该时间的字符串值
with语句的使用
with(object)
{
statements ;
}
说明:在存取对象属性和方法时不用重复指定参考对象.在with语句块中,凡是javascript
不识别的属性和方法都和该语句块指定的对象有关.如:
当使用与document对象有关的write()或者writeln()方法时,往往用如下形式:
document.writeln(hell!) ;
如果需要显示大量数据时,就会多次使用同样的document.writeln() ;语句,这时就可以
像下面的程序那样,把所有的以document对象为参考的对象的语句放到with语句块中,从而
达到减少语句量的目的.下面是一个with语句使用的例子:
其它类似信息

推荐信息