目录 搜索
JScript 用户指南 Jscript 基础 编写 JScript 代码 JScript 的变量 JScript 的数据类型 JScript 的运算符 控制程序的流程 JScript 函数 Jscript对象 创建自己的对象 内部对象 JScript 保留关键字 高级 JScript 创建高级对象 递归 变量范围 复制、传递和比较数据 使用数组 特殊字符 脚本问题解答 条件编译 条件编译变量 在浏览器中显示信息 使用消息框 语言参考 特性信息 Microsoft JScript 特性 - ECMA Microsoft JScript 特性 - 非-ECMA JScript 字母顺序的关健字列表 JScript 错误 JScript 运行时错误 JScript 语法错误 JScript 函数 GetObject 函数 ScriptEngine 函数 ScriptEngineBuildVersion 函数 ScriptEngineMajorVersion 函数 ScriptEngineMinorVersion 函数 JScript 方法 A-E abs 方法 acos 方法 anchor 方法 apply 方法 asin 方法 atan 方法 atan2 方法 atEnd 方法 big 方法 blink 方法 bold 方法 call 方法 ceil 方法 charAt 方法 charCodeAt 方法 compile 方法 concat 方法 (Array) concat 方法 (String) cos 方法 decodeURI 方法 decodeURIComponent 方法 dimensions 方法 encodeURI 方法 encodeURIComponent 方法 escape 方法 eval 方法 exec 方法 exp 方法 F-I fixed 方法 floor 方法 fontcolor 方法 fontsize 方法 fromCharCode 方法 getDate 方法 getDay 方法 getFullYear 方法 getHours 方法 getItem 方法 getMilliseconds 方法 getMinutes 方法 getMonth 方法 getSeconds 方法 getTime 方法 getTimezoneOffset 方法 getUTCDate 方法 getUTCDay 方法 getUTCFullYear 方法 getUTCHours 方法 getUTCMilliseconds 方法 getUTCMinutes 方法 getUTCMonth 方法 getUTCSeconds 方法 getVarDate 方法 getYear 方法 indexOf 方法 isFinite 方法 isNaN 方法 italics 方法 item 方法 J-R join 方法 lastIndexOf 方法 lbound 方法 link 方法 localeCompare 方法 log 方法 match 方法 max 方法 min 方法 moveFirst 方法 moveNext 方法 parse 方法 parseFloat 方法 parseInt 方法 pop 方法 pow 方法 push 方法 random 方法 replace 方法 reverse 方法 round 方法 S search 方法 setDate 方法 setFullYear 方法 setHours 方法 setMilliseconds 方法 setMinutes 方法 setMonth 方法 setSeconds 方法 setTime 方法 setUTCDate 方法 setUTCFullYear 方法 setUTCHours 方法 setUTCMilliseconds 方法 setUTCMinutes 方法 setUTCMonth 方法 setUTCSeconds 方法 setYear 方法 shift 方法 sin 方法 slice 方法 (Array) slice 方法 (String) small 方法 sort 方法 splice 方法 split 方法 sqrt 方法 strike 方法 sub 方法 substr 方法 substring 方法 sup 方法 T-Z tan 方法 test 方法 toArray 方法 toDateString 方法 toExponential 方法 toFixed 方法 toGMTString 方法 toLocaleDateString 方法 toLocaleLowerCase 方法 toLocaleString 方法 toLocaleTimeString 方法 toLocaleUpperCase 方法 toLowerCase 方法 toPrecision 方法 toString 方法 toTimeString 方法 toUpperCase 方法 toUTCString 方法 ubound 方法 unescape 方法 unshift 方法 UTC 方法 valueOf 方法 JScript 对象 ActiveXObject 对象 Array 对象 Boolean 对象 Date 对象 Enumerator 对象 Error 对象 Function 对象 Global 对象 Math 对象 Number 对象 Object 对象 RegExp 对象 正则表达式对象 String 对象 VBArray 对象 JScript 运算符 通用信息 运算符优先级 运算符总结 加法赋值运算符 (+=) 加法运算符 (+) 赋值运算符 (=) 按位“与”赋值运算符 (&=) 按位“与”运算符 (&) 按位左移运算符 (<<) 按位“非”运算符 (~) 按位“或”赋值运算符 (|=) 按位“或”运算符 (|) 按位右移运算符 (>>) 按位“异或”赋值运算符 (^=) 按位“异或”运算符 (^) 逗号运算符 ( 比较运算符 复合赋值运算符 条件(三目)运算符 (?:) delete 运算符 除法赋值运算符 (/=) 除法运算符 (/) in 运算符 递增 (++) 和递减 (--) 运算符 instanceof 运算符 左移赋值运算符 (<<=) 逻辑“与”运算符 (&&) 逻辑“非”运算符 (!) 逻辑“或”运算符 (||) 取余赋值运算符 (%=) 取余运算符 (%) 乘法赋值运算符 (*=) 乘法运算符 (*) new 运算符 右移赋值运算符 (>>=) 减法赋值运算符 (-=) 减法运算符 (-) typeof 运算符 无符号右移运算符 (>>>) 无符号右移赋值操作 (>>>=) void 运算符 JScript 属性 $1...$9 属性 arguments 属性 caller 属性 constructor 属性 description 属性 E 属性 global 属性 hasOwnProperty 方法 ignoreCase 属性 index 属性 Infinity 属性 input 属性($_) isProptotyeOf 方法 lastIndex 属性 length 属性 (Array) length 属性 (Function) length 属性 (String) LN10 属性 LN2 属性 LOG10E 属性 LOG2E 属性 MAX_VALUE 属性 message 属性 MIN_VALUE 属性 multiline 属性 name 属性 NaN 属性 NaN 属性 (Global) NEGATIVE_INFINITY 属性 number 属性 PI 属性 POSITIVE_INFINITY 属性 propertyIsEnumerable 属性 prototype 属性 source 属性 SQRT1_2 属性 SQRT2 属性 undefined 属性 JScript 语句 @cc_on 语句 @if 语句 @set 语句 break 语句 Comment 语句 continue 语句 do...while 语句 for 语句 for...in 语句 function 语句 if...else 语句 Labeled 语句 return 语句 switch 语句 this 语句 throw 语句 try...catch...finally 语句 var 语句 while 语句 with 语句 FileSystemObject 用户指南 FileSystemObject 对象模型 FileSystemObject 和 Scripting 运行时库参考的介绍 FileSystemObject 对象 设计 FileSystemObject 处理驱动器和文件夹 处理文件 FileSystemObject 示例代码 Scripting 运行时库参考 脚本运行时方法 Add 方法 (Dictionary) Add 方法 (Folders) BuildPath 方法 Close 方法 Copy 方法 CopyFile 方法 CopyFolder 方法 CreateFolder 方法 CreateTextFile 方法 Delete 方法 DeleteFile 方法 DeleteFolder 方法 DriveExists 方法 Exists 方法 FileExists 方法 FolderExists 方法 GetAbsolutePathName 方法 GetBaseName 方法 GetDrive 方法 GetDriveName 方法 GetExtensionName 方法 GetFile 方法 GetFileName 方法 getFileVersion 方法 GetFolder 方法 GetParentFolderName 方法 GetSpecialFolder 方法 GetTempName 方法 Items 方法 Keys 方法 Move 方法 MoveFile 方法 MoveFolder 方法 OpenAsTextStream 方法 OpenTextFile 方法 Read 方法 ReadAll 方法 ReadLine 方法 Remove 方法 RemoveAll 方法 Skip 方法 SkipLine 方法 Write 方法 WriteBlankLines 方法 WriteLine 方法 脚本运行时对象 Dictionary 对象 Drive 对象 Drives 集合 File 对象 Files 集合 FileSystemObject 对象 Folder 对象 Folders 集合 TextStream 对象 脚本运行时属性 AtEndOfLine 属性 AtEndOfStream 属性 Attributes 属性 AvailableSpace 属性 Column 属性 CompareMode 属性 Count 属性 DateCreated 属性 DateLastAccessed 属性 DateLastModified 属性 Drive 属性 DriveLetter 属性 Drives 属性 DriveType 属性 Files 属性 FileSystem 属性 FreeSpace 属性 IsReady 属性 IsRootFolder 属性 Item 属性 Key 属性 Line 属性 Name 属性 ParentFolder 属性 Path 属性 RootFolder 属性 SerialNumber 属性 ShareName 属性 ShortName 属性 ShortPath 属性 Size 属性 SubFolders 属性 TotalSize 属性 Type 属性 VolumeName 属性 正则表达式简介 正则表达式 早期起源 使用正则表达式 正则表达式语法 建立正则表达式 优先权顺序 普通字符 特殊字符 非打印字符 字符匹配 限定符 定位符 选择和编组 后向引用
文字


内部对象

Microsoft Jscript 提供了 11 个内部(或“内置”)对象。它们是ArrayBooleanDateFunctionGlobalMathNumberObjectRegExpError 以及 String 对象。每一个对象有相关的方法和属性,这在语言参考中有详细的描述。本节中也描述了某些对象。

Array 对象

数组下标可以被认为是对象的属性,它是通过数字索引来引用的。注意添加到数组中的已命名的属性不能通过数字来索引;它们是与数组元素分离的。

使用 new 运算符和 Array() 构造器 生成一个新的数组,如下面的示例。

var theMonths = new Array(12);
theMonths[0] = "Jan";
theMonths[1] = "Feb";
theMonths[2] = "Mar";
theMonths[3] = "Apr";
theMonths[4] = "May";
theMonths[5] = "Jun";
theMonths[6] = "Jul";
theMonths[7] = "Aug";
theMonths[8] = "Sep";
theMonths[9] = "Oct";
theMonths[10] = "Nov";
theMonths[11] = "Dec";

用关键字 Array 生成数组时,Jscript 包含了 length 属性,该属性记录了数组入口数。如果没有给该属性指定值,则设置长度为 0 且数组没有入口点。如果指定一个数值,则将长度设置为该数。如果指定了不止一个参数,则这些参数被用作数组的入口。另外,参数的数目被赋给 length 属性。如下面的示例与前一个示例是等价的。

var theMonths = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", 
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

当向用关键字 Array 生成的数组中添加元素时,Jscript 自动改变属性 length 的值。Jscript 中的数组索引总是以 0 开始,而不是 1,所以属性 length 通常比数组的最大索引大 1。

String对象

在 Jscript 中,可以将字符串(和数)当作对象来处理。string 对象 有一些内置方法,可以和自己的字符串一起使用。其中一个是substring 方法,它返回字符串的一部分。该方法以两个数字作为参数。

aString = "0123456789";
var aChunk = aString.substring(4, 7);  //  aChunk 设为 "456"var aNotherChunk = aString.substring(7, 4);  //  aNotherChunk 设为 "456"// 使用上面生成数组的示例:
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 属性,如下例所示。

// 声明一个半径变量并赋数值。
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,或者“全球标准时间”,它引用的信号是由“世界时间标准”发布的)。Jscript 可以处理 250,000 B.C. 到 255,000 A.D范围内的日期。

使用 new 运算符创建一个新的 Date 对象。下面的示例计算当年已过去的天数和今年剩下的天数。


var thisIsToday = new Date();

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

// 提取年,月,日。
var thisYear = toDay.getFullYear();
var thisMonth = theMonths[toDay.getMonth()];
var thisDay = thisMonth  + " " + toDay.getDate() + ", " + thisYear;

Number 对象

除了 Math 对象中可用的特殊数值属性(例如 PI)外,在 Microsoft Jscript 中, Number 对象有几个其他的数值属性。

属性 描述
MAX_VALUE 可能的最大数大约为 1.79E+308;可以是正数或负数。(具体数值随系统不同而有微小差别。)
MIN_VALUE 可能的最小数大约为 2.22E-308;可以是正数或负数。(具体数值随系统不同而有微小差别。)
NaN 特殊非数量值,“不是数值”。
POSITIVE_INFINITY 比最大正数(Number.MAX_VALUE)还要大的任意正值自动被转换为此值,代表正无穷大。
NEGATIVE_INFINITY 比最小的负数(负的 Number.MAX_VALUE)还小的任意值被自动转换为此值,代表负无穷。

Number.NaN 是一个特殊的属性,被定义为“不是数值”。例如被 0 除返回 NaN。试图解析一个无法被解析为数字的字符串同样返回 Number.NaN。把 NaN 与任何数值或本身作比较的结果都是不相等。不能通过与 Number.NaN 比较来测试 NaN 结果,而应该使用 isNaN() 函数。

上一篇: 下一篇: