1,<% @ LANGUAGE = Jscript %> 2,注釋 //... /*...*/ 3,申明變量 var myvar,myvar2; 4,時(shí)間與日期對(duì)象: <% mydata = new Date() %> mydate.getDate() //day of month mydate.getDay() //day of week mydate.getYear() //year other method: setMonth(),set.Date(),setYear()... 5,字符串對(duì)象: <% mydate = new string("string") %> other method: blink(),big(),small(),fixed(),italics(),strike(),sub(),sup() 分割和搜索: indexOf("string") //從左到右搜索,返回整數(shù)string的位置 lastIndexOf("string",number) //從右到左搜索,由number開(kāi)始,返回值同上。 charAt(number) //輸出number所在的字符 substring(number,number2) //輸出number to number2的字符串 length //返回字符串長(zhǎng)度 toUpperCase() //輸出大寫(xiě) toLowerCase() //輸出小寫(xiě) 6,數(shù)學(xué)對(duì)象 Math 常方法:cos(),sin(),tan(),acos(),asin(),atan(),min(),max() 附加方法:exp(),log(),pow(),sqrt() 舍入方法:abs(),round(),floor(),ceil() 隨機(jī)數(shù)方法:random() //返回0~1的數(shù)值 <%=Math.round(number*Math.random() %> //輸出一個(gè)0~number的隨機(jī)數(shù) 數(shù)學(xué)常數(shù):E,PI,LN2,LOG2E,SQRT1_2 7,函數(shù)對(duì)象 <% myfunc = new Function(myvar){ return myvar; } %> 8,數(shù)組對(duì)象 <% myarray = new Array(10); myarray[0] = "string"; .... myarray[9] ="string"; //第10個(gè)變量,與VBscript不同 %> <% myarray.length = number%> //改變數(shù)組的長(zhǎng)度 other method: reverse() //顛倒索引順序 join() //合并成單個(gè)字符串 sort() //按字母順序排列,參數(shù)可為正,負(fù)數(shù) 9,自定義對(duì)象 <% function obiect(name,password){ //定義對(duì)象 this.name = name; //this就是正在使用的對(duì)象 this.password = "unknow"; } %> <% functin expirepassword(){ //定義函數(shù) this.password = "no"; } function obiect(name,password){ this.name = name; this.password = "unknow"; this.expirepassword=expiirepassword; // 加入前定義的方法 } %> 10,Jscript函數(shù) parseInt() //字符串轉(zhuǎn)為整數(shù) parseFloat() //字符串轉(zhuǎn)為浮點(diǎn)數(shù) 運(yùn)算符 +,-,*,/,%,<,>,!=,== 11,if ... else 12, for <% for(i=0;i<10;++i){ %> // insert html <% } %> 13,指定缺省對(duì)象 with <% with(Math){ i=random(); j=random(); } %>