zoukankan      html  css  js  c++  java
  • js -- 对象

    一:创建对象的三种方法

         //方法一
            people = new Object();
            people.name = "wyp";
            people.age = "22";
            document.write("name : " + people.name + ", age :" + people.age);
    
            //方法二
            person = {
                name: "wyp",
                age: "22"
            };
            document.write(person.name + person.age);
    
            //方法三 使用函数创建对象 
            function p(name, age) {
                this.name = name;
                this.age = age;
            }
            p1 = new p("wyp", 22);
            document.write(p1.name + p1.age); //输出 wyp22

    二:String 字符串 对象

            //String 字符串对象
            var str = "hello world";
            document.write(str.length); //输出11
            //indexOf 查找字符串在字符串中的位置 存在返回在字符串中的位置
            document.write(str.indexOf("world")); //输出6
            document.write(str.indexOf("t"));     //返回-1
            //内容匹配 match 
            document.write(str.match("world"));   //打印出 world
            document.write(str.match("1"));      //打印出 null
            //replace 字符串替换
            document.write(str.replace("world","wyp"));
            //字符串大小写转换 toUpperCase() toLowerCase
            //split
            var str1 = "hello|world";
            var s1 = str1.split("|");
            document.write(s1[0]);    //输出 hello    

     三 : Date 日期对象

     四 : Array 对象

     五 : Math 对象 

     六:history 对象

     七:location 对象

     八:screen 对象

    拼命敲
  • 相关阅读:
    Interrupt、Interrupted、IsInterrupted
    ReentrantLock
    tcp粘包、拆包
    jstat 分析应用垃圾回收状况
    CopyOnWriteArrayList
    storm基础概念
    余弦距离
    websocket
    awk
    sed
  • 原文地址:https://www.cnblogs.com/wuyuwuyueping/p/9037047.html
Copyright © 2011-2022 走看看