码迷,mamicode.com
首页 > 其他好文 > 详细

内置对象

时间:2016-05-18 23:37:20      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

内置对象
1、Date
var now = new Date(); 获取当前时间
now.toUTCString() 转化为字符串格式
now.getFullYear() 年
now.getMonth() 月要+1
now.getDate() 日
now.getDay() 一周的某一天
now.getHours() 时
now.getSeconds() 秒
now.getMinutes() 分
2、String
var str = new String("abc");
var str = "abc";

str.replace("a","b"); b替换a
str.slice(a,b) a开始b结束 ,左闭右开,负数时表示倒数
str.split(",") 根据,来分割字符串成为数组

3、Math
Math.floor(num)取整,舍掉小数位,比parseIn性能好
Math.round(num)四舍五入
Math.random(num)0-1之间的随机数

this、global、window
this = window;
global会拥有宿主的所有属性
global和window对象的属性是一模一样的
window 包含自己的


正则
var inputStr = prompt("请输入");

var regExp = /^-?\d+(\.\d+)?$/;(整数或者小数)
regExp = /^\d{5}$/; (只能输入5位的正整数。)
regExp = /^[A-z]{9}$/; (只能输入9个大小写字母。)
regExp = /^.{3}$/; (只能输入长度为3的字符串。)
regExp = /^[\u4e00-\u9fa5]{3,5}$/;(只能输入3到5个汉字。)

alert(regExp.test(inputStr)); 。
具体的属性对照文哥给的文件查找,主要会用正则的写法 格式。/^&/ (^表示开始&结束。套路)
{a,b}表示a到 b个数

内置对象

标签:

原文地址:http://www.cnblogs.com/270515987q/p/5507045.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!