当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 初学JavaScript第二章

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第二章


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

初学JavaScript时觉得应该注意的一些知识点.(从<<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 ;
}
<input type="button" value="下一个" onClick="goNextAnchor('sec2')"/>
数组对象的创建:
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语句使用的例子:
<script language="javascript">
<!--
With(document)
{
write("thtwin") ;
write("thtwinj2ee") ;
wirte("test") ;
}
//-->
</script>