分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

js -- 对象

发布时间:2023-09-06 01:54责任编辑:彭小芳关键词: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 ???

js -- 对象

原文地址:https://www.cnblogs.com/wuyuwuyueping/p/9037047.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved