^ 代表开始 $ 代表结束 var txt = "123abc456"; var reg=/\d+/ 只要其中有一部分满足 第二个 结果就为true var txt = "12v3"; var reg = /^\d+$/ //如果内容全是数字 则 结果为TRUE 若以字母开头则结果为false // 开始与结束都为数字结果为true console.log(reg.test(txt)) 1[3-9]\d{9} \d{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01]) 年月日日期 [\u4e00-\u9fa5] 常用汉字范围 \u4e00\u4e00 单字节 JS的调用方法: 第一种: var student={ id:10001, name:"张三", scores:[ {subject:"html",score:90}, { subject:"JS",score:90} ] } console.log(student.scores); //调用结果 结果为: [ { subject: 'html', score: 90 }, { subject: 'JS', score: 90 } ] 第二种:利用function function Student(id,name){ this.id = id; this.name = name; this.scores = [ {subject:"html",score:90}, { subject:"JS",score:90} ] } Student.prototype.sex="男"; //prototype 代表 扩充 Student.prototype.eat = function(food){ //扩展 console.log("吃" + food) } var stu = new Student(1000,"张三"); stu.eat("米饭"); console.log(stu.sex) 结果为: 吃米饭 男 Object 第三种: var stu2 = new Object(); stu2.name="张三"; stu2.scores =[ {subject:"html",score:90}, { subject:"JS",score:90} ] 链式编程: function Student(id,name){ this.id = id; this.name=name; this.eat =function(food){ console.log("吃"+food) return this }, this.sleep = function(){ console.log("睡") return this } }
var stu = new Student(1001,"张三"); stu.eat("").sleep().eat("").sleep().eat("").sleep().eat("").sleep(); //链式编程