JavaScript---函数

1、 函数的定义
function   函数名(参数列表)
{     代码块
   }


--   作者:111
--   发布时间:2004-12-3 1:31:00

--  

2、 函数的调用
     函数名(参数列表)
3、 javascript 的全局函数
(1) eval(字符串)
执行该字符串
(2)   parseInt(字符串,[基数])   parseFloat(字符串)
var s="3.14"
var j=parseInt(s)
var k=parseFloat(s)
         parseInt("2B",16)=
(3) isNaN(表达式) :不是数字
(4) Number(对象)和 String(对象)
Var n=new Number(20)
document.write(n.toString(16))
(5) Escape(字符串)和unescape(字符串)将消息串格式转换为ASC码格式
4、 方法
(1) 滚动窗口scroll()
   scroll(x,y):移至窗口某一点,左上角为0,0     [winscroll.htm]
(2) 设置延迟setTimeout("表达式",时间) 时间:以毫秒为单位
(3) 清除延迟clearTimeout("延迟号")
如:id=setTimeout("disp()",1000)  
     clearTimeout(id)
(4)

五、 Javascript 中的对象
1、 建立自定义对象
方法1:对象={属性1:属性值1,属性2:属性值2……属性n:属性值n}
   方法2:先定义构造函数,再new创建对象实例。
     如: function car(thecolor,thenumber,thewheels)
           { this.color=thecolor;
             this.number=thenumber;
             this.wheels=thewheels;   }

     var   mycar=new car("RED","13245",4);
2、 定义对象的方法     [oop.htm]
     function ReportInfo( )
   { var information=new string;
     information="color:"+this.color+"<BR>";
     information+="Number:"+this.Number+"<BR>";
     information+="Wheels"+this.wheels;
     window.document.write(information);
   }

3、 javascript核心语言对象
(1) 数组对象(Array)
   建立数组:var st=new Array("zhang","wang","li","chen");
             var st1=new Array(4)
   访问数组元素: st[2]
   数组对象的属性 length (长度)     [forin.htm]
             方法 sort( )   按ASCII码排序   sort([比较函数名])   [sort.htm]
                       比较函数返回值(a与b比较)   <0   b排在a 的前面
                                                 =0   保持原来次序
                                                 >0   a排在b的前面
                   reverse( )   元素颠倒顺序
                   join(分隔符) 转换成字符串
            
(2) 字符串对象(String)
       属性: length
       方法:toUpperCase()   转换为大写字母
             toLowerCase()   转换为小写字母
             indexOf(字符串,起始位置)   返回子字符串在字符串中的位置,若没有,则为-1
             LastIndexOf(字符串,起始位置) 返回子字符串在字符串中最后的位置
             charAt(位置)   返回字符串中下标位置的字母
             substring(位置1,位置2)返回位置1,位置2间字符串
             split(分界符) 按分界符的分解成数组元素
             以下的为格式化字符串方法 [str.htm]
             big()   blink()   bold()   fixed()   fontcolor()   fontsize()   italics() small()
             strike()   sub()   sup()

posted @ 2018-03-05 15:11  _小董  阅读(76)  评论(0编辑  收藏  举报