PHP4 | Flash | ASP | CSS | VBScript | ADO | MySQL | JavaScript | Spring | Hibernate | win32api | 正则表达式 | 注册表 | xmlhttp .
当前位置:首页 → javascript上一篇 使用消息框    下一篇 脚本问题解答
在当前chm中查找:
目录
·什么是 JScript?
·使用消息框
·固有对象
·脚本问题解答
·控制程序的流程
·创建高级对象
·创建自己的对象
·的数据类型
·JScript 的变量
·FileSystemObject 词汇
·JScript 的函数
·JScript 词汇表
· 按字母顺序排列的关键字列表
·运算符操作
·concat 方法 (数组)
·concat 方法 (Array)
·concat 方法 (Array)
·join 方法
·join 方法
·join 方法
·length 属性 (Array)
·length 属性 (Array)
·length 属性 (Array)
·reverse 方法
·reverse 方法
·reverse 方法
·slice 方法 (Array)
·slice 方法
·slice 方法
·sort 方法
·sort 方法
·sort 方法
·Drives 集合
·Drives 集合
·Drives 集合
·Drives 集合
·Files 集合
·Files 集合
·Files 集合
·Files 集合
·Folders 集合
·Folders 集合
·Folders 集合
·Folders 集合
·条件编译
·条件编译
·条件编译变量
·条件编译变量
·getDate 方法
·getDate 方法
·getDate 方法
·getDay 方法
·getDay 方法
·getDay 方法
·getFullYear 方法
·getFullYear 方法
·getFullYear 方法
·getHours 方法
·getHours 方法
·getHours 方法
·getMilliseconds 方法
·getMilliseconds 方法
·getMilliseconds 方法
·getMinutes 方法
·getMinutes 方法
·getMinutes 方法
·getMonth 方法
·getMonth 方法
·getMonth 方法
·getSeconds 方法
·getSeconds 方法
·getSeconds 方法
·getTime 方法
·getTime 方法
·getTime 方法
·getTimezoneOffset 方法
·getTimezoneOffset 方法
·getTimezoneOffset 方法
·getUTCDate 方法
·getUTCDate 方法
·getUTCDate 方法
·getUTCDay 方法
·getUTCDay 方法
·getUTCDay 方法
·getUTCFullYear 方法
·getUTCFullYear 方法
·getUTCFullYear 方法
·getUTCHours 方法
·getUTCHours 方法
·getUTCHours 方法
·getUTCMilliseconds 方法
·getUTCMilliseconds 方法
·getUTCMilliseconds 方法
·getUTCMinutes 方法
·getUTCMinutes 方法
·getUTCMinutes 方法
·getUTCMonth 方法
·getUTCMonth 方法
·getUTCMonth 方法
·getUTCSeconds 方法
·getUTCSeconds 方法
·getUTCSeconds 方法
·getVarDate 方法
·getVarDate 方法
·getVarDate 方法
·getYear 方法
·getYear 方法
·getYear 方法
·parse 方法
·parse 方法
·parse 方法
·setDate 方法
·setDate 方法
·setDate 方法
·setFullYear 方法
·setFullYear 方法
·setFullYear 方法
·setHours 方法
·setHours 方法
·setHours 方法
·setMilliseconds 方法
·getMilliseconds 方法
·setMilliseconds 方法
·setMinutes 方法
·setMinutes 方法
· setMinutes 方法
·setMonth 方法
·setMonth 方法
·setMonth 方法
·setSeconds 方法
·setSeconds 方法
·setSeconds 方法
·setTime 方法
·setTime 方法
·setTime 方法
·setUTCDate 方法
·setUTCDate 方法
·setUTCDate 方法
·setUTCFullYear 方法
·setUTCFullYear 方法
·setUTCFullYear 方法
·setUTCHours 方法
·setUTCHours 方法
·setUTCHours 方法
·setUTCMilliseconds 方法
·setUTCMilliseconds 方法
·setUTCMilliseconds 方法
·setUTCMinutes 方法
·setUTCMinutes 方法
·setUTCMinutes 方法
·setUTCMonth 方法
·setUTCMonth 方法
·setUTCMonth 方法
·setUTCSeconds 方法
·setUTCSeconds 方法
·setUTCSeconds 方法
·setYear 方法
·setYear 方法
·setYear 方法
·toGMTString 方法
·toGMTString 方法
·toGMTString 方法
·toLocaleString 方法
·toLocaleString 方法
·toLocaleString 方法
·toUTCString 方法
·toUTCString 方法
·toUTCString 方法
·UTC 方法
·UTC 方法
·UTC 方法
·Add 方法 (Dictionary)
·Add 方法 (Dictionary)
·CompareMode 属性
·CompareMode 属性
·CompareMode 属性
·Count 属性
·Count 属性
·Count 属性
·Exists 方法
·Exists 方法
·Exists 方法
·Item 属性
·Item 属性
·Item 属性
·Items 方法
·Items 方法
·Items 方法
·Key 属性
·Key 属性
·Key 属性
·Keys 方法
·Keys 方法
·Keys 方法
·Remove 方法
·Remove 方法
·RemoveAll 方法
·RemoveAll 方法
·RemoveAll 方法
·Remove 方法
·AvailableSpace 属性
·AvailableSpace 属性
·AvailableSpace 属性
·DriveLetter 属性
·DriveLetter 属性
·DriveLetter 属性
·DriveType 属性
·DriveType 属性
·DriveType 属性
·FileSystem 属性
·FileSystem 属性
·FileSystem 属性
·FreeSpace 属性
·FreeSpace 属性
·FreeSpace 属性
·IsReady 属性
·IsReady 属性
·IsReady 属性
·Path 属性
·Path 属性
·Path 属性
·RootFolder 属性
·RootFolder 属性
·RootFolder 属性
·SerialNumber 属性
·SerialNumber 属性
·SerialNumber 属性
·ShareName 属性
·ShareName 属性
·ShareName 属性
·TotalSize 属性
·TotalSize 属性
·TotalSize 属性
·VolumeName 属性
·VolumeName 属性
·VolumeName 属性
·atEnd 方法
·atEnd 方法
·atEnd 方法
·item 方法
·item 方法
·item 方法
·moveFirst 方法
·moveFirst 方法
·moveFirst 方法
·moveNext 方法
·moveNext 方法
·moveNext 方法
· JScript 错误
· 特性信息
·Attributes 属性
·Attributes 属性
·Attributes 属性
·Copy 方法
·Copy 方法
·Copy 方法
·CreateTextFile 方法
·CreateTextFile 方法
·CreateTextFile 方法
·DateCreated 属性
·DateCreated 属性
·DateCreated 属性
·DateLastAccessed 属性
·DateLastAccessed 属性
·DateLastAccessed 属性
·DateLastModified 属性
·DateLastModified 属性
·DateLastModified 属性
·Delete 方法
·Delete 方法
·Delete 方法
·Drive 属性
·Drive 属性
·Drive 属性
·Move 方法
·Move 方法
·Move 方法
·Name 属性
· Name 属性
·Name 属性
·OpenAsTextStream 方法
·OpenAsTextStream 方法
·OpenAsTextStream 方法
·OpenTextFile 方法
·OpenTextFile 方法
·OpenTextFile 方法
·ParentFolder 属性
·ParentFolder 属性
·ParentFolder 属性
·ShortName 属性
·ShortName 属性
·ShortName 属性
·ShortPath 属性
·ShortPath 属性
·ShortPath 属性
·Size 属性
·Size 属性
·Size 属性
·BuildPath 方法
·BuildPath 方法
·BuildPath 方法
·CopyFile 方法
·CopyFile 方法
·CopyFile 方法
·CopyFolder 方法
·CopyFolder 方法
·CopyFolder 方法
·CreateFolder 方法
·CreateFolder 方法
·CreateFolder 方法
·DeleteFile 方法
·DeleteFile 方法
·DeleteFile 方法
·DeleteFolder 方法
·DeleteFolder 方法
·DeleteFolder 方法
·DriveExists 方法
·DriveExists 方法
·DriveExists 方法
·Drives 属性
·Drives 属性
·Drives 属性
·FileExists 方法
·FileExists 方法
·FileExists 方法
·FolderExists 方法
·FolderExists 方法
·FolderExists 方法
·GetAbsolutePathName 方法
·GetAbsolutePathName 方法
·GetAbsolutePathName 方法
·GetBaseName 方法
·GetBaseName 方法
·GetBaseName 方法
·GetDrive 方法
·GetDrive 方法
·GetDrive 方法
·GetDriveName 方法
·GetDriveName 方法
·GetDriveName 方法
·GetExtensionName 方法
·GetExtensionName 方法
·GetExtensionName 方法
·GetFile 方法
·GetFile 方法
·GetFile 方法
·GetFileName 方法
·GetFileName 方法
·GetFileName 方法
·GetFileVersion 方法
·GetFileVersion 方法
·GetFileVersion 方法
·GetFolder 方法
·GetFolder 方法
·GetFolder 方法
·GetParentFolderName 方法
·GetParentFolderName 方法
·GetParentFolderName 方法
·GetSpecialFolder 方法
·GetSpecialFolder 方法
·GetSpecialFolder 方法
·GetTempName 方法
·GetTempName 方法
·GetTempName 方法
·MoveFile 方法
·MoveFile 方法
·MoveFile 方法
·MoveFolder 方法
·MoveFolder 方法
·MoveFolder 方法
·Type 属性
·Type 属性
·Type 属性
·GetObject 函数
·GetObject 函数
·ScriptEngine 函数
·ScriptEngineBuildVersion 函数
·ScriptEngineBuildVersion 函数
·ScriptEngine 函数
·ScriptEngineMajorVersion 函数
·ScriptEngineMajorVersion 函数
·ScriptEngineMinorVersion 函数
·ScriptEngineMinorVersion 函数
·Add 方法 (Folders)
·Add 方法 (Folders)
·Add 方法 (Folders)
·Files 属性
·Files 属性
·Files 属性
·IsRootFolder 属性
·IsRootFolder 属性
·IsRootFolder 属性
·SubFolders 属性
·SubFolders 属性
·SubFolders 属性
·Microsoft(R) JScript 运行时库参考
·JScript 教程
· 函数
·arguments 属性
·arguments 属性
·arguments 属性
·caller 属性
·caller 属性
·caller 属性
·length 属性 (Function)
·length 属性
·length 属性 (Function)
·escape 方法
·escape 方法
·escape 方法
·eval 方法
·eval 方法
·eval 方法
·Infinity 属性
·Infinity 属性
·Infinity 属性
·isFinite 方法
·isFinite 方法
·isFinite 方法
·isNaN 方法
·isNaN 方法
·isNaN 方法
·NaN 属性 (Global)
·NaN 属性
·NaN 属性
·parseFloat 方法
·parseFloat 方法
·parseFloat 方法
·parseInt 方法
·parseInt 方法
·parseInt 方法
·unescape 方法
·unescape 方法
·unescape 方法
·JScript 比较运算符
·比较运算符
·Microsoft JScript 特性 - ECMA
·Microsoft JScript 特性 - 非-ECMA
·Microsoft Scripting 运行时特性
·abs 方法
·abs 方法
·abs 方法
·acos 方法
·acos 方法
·acos 方法
·asin 方法
·asin 方法
·asin 方法
·atan 方法
·atan2 方法
·atan2 方法
·atan2 方法
·atan 方法
·atan 方法
·ceil 方法
·ceil 方法
·ceil 方法
·cos 方法
·cos 方法
·cos 方法
·E 属性
·E 属性
·E 属性
·exp 方法
·exp 方法
·exp 方法
·floor 方法
·floor 方法
·floor 方法
·LN10 属性
·LN10 属性
·LN10 属性
·LN2 属性
·LN2 属性
·LN2 属性
·log 方法
·LOG10E 属性
·LOG10E 属性
·LOG10E 属性
·LOG2E 属性
·LOG2E 属性
·LOG2E 属性
·log 方法
·log 方法
·max 方法
·max 方法
·max 方法
·min 方法
·min 方法
·min 方法
·PI 属性
·PI 属性
·pow 方法
·pow 方法
·pow 方法
·random 方法
·random 方法
·random 方法
·round 方法
·round 方法
·round 方法
·sin 方法
·sin 方法
·sin 方法
·sqrt 方法
·SQRT1_2 属性
·SQRT1_2 属性
·SQRT1_2 属性
·SQRT2 属性
·SQRT2 属性
·SQRT2 Property
·sqrt 方法
·sqrt 方法
·tan 方法
·tan 方法
·tan 方法
· 方法
·JScript 运行时错误
·JScript 语法错误
·MAX_VALUE 属性
·MAX_VALUE 属性
·MAX_VALUE 属性
·MIN_VALUE 属性
·MIN_VALUE 属性
·MIN_VALUE 属性
·NaN 属性
·NaN 属性
·NaN 属性
·NEGATIVE_INFINITY 属性
·NEGATIVE_INFINITY 属性
·NEGATIVE_INFINITY 属性
·POSITIVE_INFINITY 属性
·POSITIVE_INFINITY 属性
·POSITIVE_INFINITY 属性
· 对象
·ActiveXObject 对象
·ActiveXObject 对象
·Array 对象
·Array 对象
·Array 对象方法
·Array 对象属性
·Boolean 对象
·Boolean 对象
·Boolean 对象方法
·Boolean 对象属性
·Date 对象
·Date 对象
·Date 对象方法
·Date 对象属性
·Dictionary 对象
·Dictionary 对象
·Dictionary 对象方法
·Dictionary 对象属性
·Drive 对象
·Drive 对象
·Drive 对象
·Drive 对象
·constructor 属性
·constructor 属性
·constructor 属性
·prototype 属性
·prototype 属性
·prototype 属性
·toString 方法
·toString 方法
·toString 方法
·valueOf 方法
·valueOf 方法
·valueOf 方法
·Enumerator 对象
·Enumerator 对象
·Enumerator 对象
·Enumerator 对象
·Error 对象
·Error 对象
·Error 对象
·File 对象
·File 对象
·File 对象
·File 对象
·FileSystemObject 对象
·FileSystemObject 对象
·FileSystemObject 对象方法
·FileSystemObject 对象属性
·Folder 对象
·Folder 对象
·Folder 对象
·Folder 对象
·Function 对象
·Function 对象
·Function 对象方法
·Function 对象属性
·Global 对象
·Global 对象
·Global 对象
·Global 对象
·Math 对象
·Math 对象
·Math 对象方法
·Math 对象属性
·Number 对象
·Number 对象
·Number 对象方法
·Number 对象属性
·Object 对象
·Object 对象
·Object 对象
·Object 对象
·RegExp 对象
·RegExp 对象
·RegExp 对象
·RegExp 对象
·正则表达式对象
·正则表达式对象
·正则表达式对象
·正则表达式对象
·String 对象
·String 对象
·String 对象方法
·String 对象属性
·TextStream 对象
·TextStream 对象
·TextStream 对象
·TextStream 对象
·VBArray 对象
·VBArray 对象
·VBArray 对象
·VBArray 对象
· 运算符
·运算符优先级
·JScript 的运算符
·加法运算符 (+)
·加法运算符 (+)
·加法赋值运算符 (+=)
·加法赋值运算符 (+=)
·复合赋值运算符
·逻辑“与”运算符 (&&)
·逻辑“与”运算符 (&&)
·赋值运算符 (=)
·赋值运算符 (=)
·按位“与”赋值运算符 (&=)
·按位“与”赋值运算符 (&=)
·按位“或”赋值运算符 (|=)
·按位“或”赋值运算符 (|=)
·按位“与”运算符 (&)
·按位“与”运算符 (&)
·按位“非”运算符 (~)
·按位“非”运算符 (~)
·按位“或”运算符 (|)
·按位“或”运算符 (|)
·逗号运算符 (,)
·逗号运算符(,)
·条件(三目)运算符 (?:)
·条件(三元)运算符 (?:)
·delete 运算符
·delete 运算符
·除法赋值运算符 (/=)
·除法赋值运算符 (/=)
·除法运算符 (/)
·除法运算符 (/)
·递增 (++) 和递减 (--) 运算符
·递增 (++) 和递减 (--) 运算符
·instanceof 运算符
·instanceof 运算符
·运算符总结
·左移赋值运算符 (<<=)
·左移赋值运算符 (<<=)
·按位左移运算符 (<<)
·按位左移运算符 (<<)
·取余运算符 (%)
·取余赋值运算符 (%=)
·取余赋值运算符 (%=)
·乘法赋值运算符 (*=)
·乘法赋值运算符 (*=)
·乘法运算符 (*)
·乘法运算符 (*)
·new 运算符
·逻辑“非”运算符 (!)
·逻辑“非”运算符 (!)
·逻辑“或”运算符 (||)
·逻辑“或”运算符 (||)
·右移赋值运算符 (>>=)
·右移赋值运算符 (>>=)
·按位右移运算符 (>>)
·按位右移运算符 (>>)
·减法赋值运算符 (-=)
·减法赋值运算符 (-=)
·减法运算符 (-)
·减法运算符 (-)
·typeof 运算符
·typeof 运算符
·无符号右移赋值操作 (>>>=)
·无符号右移赋值运算符 (>>>=)
·无符号右移运算符 (>>>)
·无符号右移运算符 (>>>)
·void 运算符
·void 运算符
·按位“异或”运算符 (^)
·按位“异或”运算符 (^)
·按位“异或”赋值运算符 (^=)
·按位“异或”赋值运算符 (^=)
· 属性
·description 属性
·description 属性
·description 属性
·number 属性
·number 属性
·number 属性
·index 属性
·index 属性
·index 属性
·input 属性
·input 属性
·input 属性
·lastIndex 属性
·lastIndex 属性
·lastIndex 属性
·$1...$9 属性
·$1..$9 属性
·$1...$9 属性
·compile 方法
·compile 方法
·compile 方法
·exec 方法
·exec 方法
·exec 方法
·lastIndex 属性(正则表达式)
·lastIndex 属性(正则表达式)
·lastIndex 属性(正则表达式)
·source 属性
·source 属性
·source 属性
·test 方法
·test 方法
·test 方法
·正则表达式的语法
·正则表达式的语法
·正则表达式的语法
·JScript 的保留关键字
· 字母顺序的关键字列表
· 特性信息
· 方法
· 对象
· 属性
· 语句
·break 语句
·break 语句
·@cc_on 语句
·@cc_on 语句
·Comment 语句
·Comment 语句
·@if 语句
·@if 语句
·continue 语句
·continue 语句
·do...while 语句
·do...while 语句
·for 语句
·for 语句
·for...in 语句
·for...in 语句
·function 语句
·function 语句
·if...else 语句
·if...else 语句
·Labeled 语句
·Labeled 语句
·return 语句
·return 语句
·@set 语句
·switch 语句
·switch 语句
·this 语句
·this 语句
·throw 语句
·throw 语句
·try...catch 语句
·try...catch 语句
·var 语句
·var 语句
·while 语句
·while 语句
·with 语句
·with 语句
·anchor 方法
·anchor 方法
·anchor 方法
·big 方法
·big 方法
·big 方法
·blink 方法
·blink 方法
·blink 方法
·bold 方法
·bold 方法
·bold 方法
·charAt 方法
·charAt 方法
·charAt 方法
·charCodeAt 方法
·charCodeAt 方法
·charCodeAt 方法
·concat 方法(String)
·concat 方法(字符串)
·concat 方法(字符串)
·fixed 方法
·fixed 方法
·fixed 方法
·fontcolor 方法
·fontcolor 方法
·fontcolor 方法
·fontsize 方法
·fontsize 方法
·fontsize 方法
·fromCharCode 方法
·fromCharCode 方法
·fromCharCode 方法
·indexOf 方法
·indexOf 方法
·indexOf 方法
·italics 方法
·italics 方法
·italics 方法
·lastIndexOf 方法
·lastIndexOf 方法
·lastIndexOf 方法
·length 属性(字符串)
·length 属性(String)
·length 属性(String)
·link 方法
·link 方法
·link 方法
·match 方法
·match 方法
·match 方法
·replace 方法
·replace 方法
·replace 方法
·search 方法
·search 方法
·search 方法
·slice 方法 (String)
·slice 方法 (String)
·slice 方法 (String)
·small 方法
·small 方法
·small 方法
·split 方法
·split 方法
·split 方法
·strike 方法
·strike 方法
·strike 方法
·sub 方法
·sub 方法
·sub 方法
·substr 方法
·substr 方法
·substr 方法
·substring 方法
·substring 方法
·substring 方法
·sup 方法
·sup 方法
·sup 方法
·toLowerCase 方法
·toLowerCase 方法
·toLowerCase 方法
·toUpperCase 方法
·toUpperCase 方法
·toUpperCase 方法
·AtEndOfLine 属性
·AtEndOfLine 属性
·AtEndOfLine 属性
·AtEndOfStream 属性
·AtEndOfStream 属性
·AtEndOfStream 属性
·Close 方法
·Close 方法
·Close 方法
·Column 属性
·Column 属性
·Column 属性
·Line 属性
·Line 属性
·Line 属性
·Read 方法
·Read 方法
·ReadAll 方法
·ReadAll 方法
·ReadAll 方法
·Read 方法
·ReadLine 方法
·ReadLine 方法
·ReadLine 方法
·Skip 方法
·Skip 方法
·Skip 方法
·SkipLine 方法
·SkipLine 方法
·SkipLine 方法
·Write 方法
·Write 方法
·WriteBlankLines 方法
·WriteBlankLines 方法
·WriteBlankLines 方法
·Write 方法
·WriteLine 方法
·WriteLine 方法
·WriteLine 方法
·Microsoft(R) JScript 语言参考
·JScript 教程
·JScript 教程
·数据类型转换
·dimensions 方法
·dimensions 方法
·dimensions 方法
·getItem 方法
·getItem 方法
·getItem 方法
·lbound 方法
·lbound 方法
·lbound 方法
·toArray 方法
·toArray 方法
·toArray 方法
·ubound 方法
·ubound 方法
·ubound 方法
·版本信息
·JScript 的对象
·递归
·变量范围
·FileSystemObject 对象
·FileSystemObject 示例代码
·Microsoft(R) Scripting 库 - FileSystemObject 和 Scripting 运行时库参考的介绍
·设计 FileSystemObject
·Microsoft(R) Scripting 库 - FileSystemObject 对象
·处理驱动器和文件夹
·处理文件
·特殊字符
·编写 JScript 代码
·使用数组
·复制、传递和比较数据
·在浏览器中显示信息
固有对象

固有对象
 JScript 教程 
 上一个 



www.51chm.com

Microsoft JScript 提供了九个固有(或称“内置”)对象。它们是 ArrayBooleanDateFunctionGlobalMathNumberObjectString 对象。 每个固有对象都有与之关联的方法和属性,这些方法和属性均在语言参考中详细描述。 这里描述了几个对象。
Array 对象
在 JScript 中,对象作为数组处理,数组作为对象处理。数组的下标完全等价于对象的属性,可以按数字引用(如果对其指定了名称,则也可以按名称来引用)。要创建一个新数组,请使用 new 运算符和 Array() 构造函数,如下例所示。
var theMonths = new Array(12)  {
theMonths[0] = "一月";
theMonths[1] = "二月";
theMonths[2] = "三月";
theMonths[3] = "四月";
theMonths[4] = "五月";
theMonths[5] = "六月";
theMonths[6] = "七月";
theMonths[7] = "八月";
theMonths[8] = "九月";
theMonths[9] = "十月";
theMonths[10] = "十一月";
theMonths[11] = "十二月";
}
在使用 Array 关键字来创建数组时,JScript 在该数组中包括了一个只写的 length 属性,用来记录数组中的项数。如果您没有指定一个数值,则 length 被设置为 0,且数组没有任何项。如果您指定了一个数值,则 length 被设置为该数值。如果您指定了多个参数,则这些参数将作为数组的项,并将参数的个数指定给 length 属性,如下例所示。该示例与上一节示例等价。
var theMonths = new Array("一月", "二月", "三月", "四月", "五月", "六月", 
"七月", "八月", "九月", "十月", "十一月", "十二月");
对于使用 Array 关键字创建的数组,当给数组添加元素时,JScript 将自动更改 length 的数值。
String 对象
在 JScript 中字符串是对象。这意味着在任何时候声明一个字符串变量或使用一个字符串文字,实际上就是创建一个新的字符串对象。String 对象有若干内置方法,您可以对该字符串使用这些方法。其中一个方法是 substring 方法,用于返回该字符串的一部分。该方法需要两个数字作为其参数。
aString = "0123456789";
var aChunk = aString.substring(4, 7);  // 将 aChunk 设置为 "456"。
var aNotherChunk = aString.substring(7, 4);  // 将 aNotherChunk 设置为 "456"。

// 使用前面的 Array 创建示例:
firstLetter = theMonths [5].substring(0,1);  // 将 firstLetter 变量设置为 "J"。
String 对象的另一个属性是 length 属性。该属性包含该字符串中的字符个数,如果是空字符串则该属性为 0。这是一个数值型数值,并可以在计算中直接使用。
var howLong = "Hello World".length  // 将 howLong 变量设置为 11。
Math 对象
Math 对象有许多属性和方法,全部都是预定义的。这些属性都是特定数值。其中一个是 pi 的值(近似为 3.14159...)。下面就是 Math.PI 属性的示例。
//  radius 变量已经声明并赋值。
var circleArea = Math.PI * radius * radius;  // 注意 Math 和 PI 的大写。
Math 对象的内置方法之一是求幂,即 pow 方法,求一个数的指定幂次。下例使用了 pi 属性和求幂方法。
// 该公式计算给定半径的球体的体积。
volume = (4/3)*(Math.PI*Math.pow(radius,3));
Date 对象
使用 Date 对象可获得当天的日期,并计算日期之间的间隔。该对象有许多属性和方法,都是预定义的。通常, Date 对象提供了星期几、月、日、年;以及包括时、分、秒的时间信息。该信息以从 1970 年 1 月 1 日 00:00:00.000 GMT 以来的毫秒数为基准。GMT 代表“格林尼治标准时间”;更标准的术语是 UTC 或曰“全球标准时间”,这是由世界时间标准组织(World Time Standard)发布的符号。



www.51chm.com
注意  就 JScript 而言,时间是从 1970 年 1 月 1日的午夜开始的,您不能让 JScript 创建一个 Date 对象来表示在此之前的时间。如果需要处理更早的时间,您必须自己编写代码实现,这可是一个艰巨的任务。


www.51chm.com

要创建一个新的 Date 对象,您可以使用 new 运算符。下面的示例计算今年已经过去的天数和还剩下的天数。

/*
该示例使用了前面定义的月份数组。第一个语句将今天的日期指定给 thisIsToday,其格式为 "周工作日 月份 日 00:00:00 年份"。
*/
var thisIsToday = new Date();

var toDay = new Date();  // 获取今天的日期。

// 提取年、月、日信息。
var thisYear = toDay.getYear() + 1900;
var thisMonth = theMonths[toDay.getMonth()];
var thisDay = thisMonth  + " " + toDay.getDate() + "," + (parseInt(toDay.getYear()) + 1900);

// 确定从开始以来的天数 #。
thisDay = Math.round(Date.parse(thisDay)/8.64e7);

// 对今年的第一天采取同样的操作。
var firstDay = "Jan 1, " + thisYear;
firstDay = Math.floor(Date.parse(firstDay)/8.64e7); 

// 对今年的最后一天在此采取同样的操作,以防止闰年。
var lastDay = "Dec 31, " + thisYear;
lastDay = Math.floor(Date.parse(lastDay)/8.64e7);

// 计算这一年的天数。
var daysInYear = (lastDay - firstDay) + 1;

// 确定已过去多少天,还剩下多少天。
var daysElapsed = thisDay - firstDay;
var daysLeft = daysInYear - daysElapsed; 

// 对普遍情况建立评论。
var comment1 = "今年已过去 " + daysElapsed+ " 天。";
var comment2 = "这意味着在 " + "thisYear" + " 还有 " + daysLeft + " 天。";

// 包含特殊情况:一年的开始&结束,以及只剩一天。
if (daysElapsed == 0)  {
comment1 = "今天是 " + thisYear + " 的 1 月 1 日。";
}
if (daysElapsed == 1) {
comment1 = "只过去了一天。";
}
if(daysElapsed == daysInYear) {
comment1 = thisYear + " 快要结束了。";
}

if (daysLeft == 0)  {
comment2 = "新年最诚挚的祝福!";
}
if (daysLeft == 1)  {
comment2 = thisYear + "只剩下一天了。";
}
if (daysLeft == daysInYear)  {
comment2 = "新年快乐!";
}
Number 对象
除了在 Math 对象中可用的特定数值属性(例如 PI )之外,在 Microsoft JScript 中还可以由 Number 对象得到若干其他属性。

属性描述
MAX_VALUE最大的可能数值,大约为 1.79E+308; 可以是正数也可以是负数。(对不同的系统这个数值有稍许变化。)

MIN_VALUE最小的可能数值,大约为 2.22E-308;可以是正数也可以是负数。(对不同的系统这个数值有稍许变化。)
NaN专用的非数值型取值,“不是一个数。”
POSITIVE_INFINITY任何比 Number.MAX_VALUE 大的正数
都将自动转换为这个值;用 "Inf" 表示。
NEGATIVE_INFINITY任何比 -Number.MAX_VALUE 更小的负数
都将自动转换为这个值;用 "-Inf" 表示。

Number.NaN 是一个特别的属性,被定义为“不是一个数”。例如,除零操作将返回 NaN。对一个不能解释为数值的字符串进行转换也将返回 Number.NaNNaN 不等于任何数值,也不等于它本身。如果要对 NaN 结果进行测试,请不要对 Number.NaN 进行比较;而应使用 isNaN() 函数。



www.51chm.com
更多内容
·控制程序的流程
·创建高级对象
·创建自己的对象
·的数据类型
·JScript 的变量
·FileSystemObject 词汇
·JScript 的函数
·JScript 词汇表
· 按字母顺序排列的关键字列表
·运算符操作
    首页 |  友情链接 |  网站地图      京ICP备07034540号    © 2007 www.51chm.com       Powered by xichy{at}163.com