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

JaScript中的常用对象

时间:2015-01-25 16:29:46      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

console
console.log();    // 显示信息的命令
 
console.dir();    // 显示一个对象所有的属性和方法
console.dirxml(); // 显示网页的某个节点(node)所包含的html/xml代码
console.group() / console.groupEnd();         // 信息分组
console.profile(name) / console.profileEnd(); // 分析函数的执行情况
console.time() / console.timeEnd();           // 用来显示代码的运行时间

 

Date
var date = new Date();
 
date.getYear();            // 获取当前年份(2位)
date.getFullYear();        // 获取完整的年份(4位,1970-????)
date.getMonth();           // 获取当前月份(0-11,0代表1月)
date.getDate();            // 获取当前日(1-31)-(这个比较特殊,第一个是1)
date.getDay();             // 获取当前星期X(0-6,0代表星期天)
 
 
date.getTime();            // 获取当前时间(从1970.1.1开始的毫秒数,等价于Date.now() )
date.getHours();           // 获取当前小时数(0-23)
date.getMinutes();         // 获取当前分钟数(0-59)
date.getSeconds();         // 获取当前秒数(0-59)
date.getMilliseconds();    // 获取当前毫秒数(0-999)
 
 
date.toLocaleString();     // 获取日期与时间(‘2014年11月3日 下午9:21:20‘)
date.toLocaleDateString(); // 获取当前日期(‘2014年11月3日‘)
date.toLocaleTimeString(); // 获取当前时间(‘下午9:21:04‘)
 
new Date(‘2014/11/3‘).getDay(); // 根据日期获取星期(1)

 

location
location.href      // 设置或获取整个 URL 为字符串
location.search    // 设置或获取 href 属性中跟在问号("?")后面的部分(含"?")
location.reload()  // 刷新网页
 
location.hash      // 设置或获取 href 属性中在井号("#")后面的部分(含"#")
location.host      // 设置或获取 location 或 URL 的 hostname 和 port 号码
location.hostname  // 设置或获取 location 或 URL 的主机名称部分
location.pathname  // 设置或获取对象指定的文件名或路径
location.port      // 设置或获取与 URL 关联的端口号码
location.protocol  // 设置或获取 URL 的协议部分
location.replace() // 打开新的网页
location.assign()  // 打开新的网页

 

Math
Math.PI               // 返回圆周率
 
Math.abs()            // 返回数值的绝对值
Math.ceil(n)          // 返回大于或等于n的最小整数
Math.cos(n)           // 计算n的余弦三角函数
Math.floor(n)         // 返回小于或等于n的最大整数
Math.max(n1, n2, ...) // 返回多个值中的最大数
Math.min(n1, n2, ...) // 返回多个值中的最小数
Math.pow(m, n)        // 幂运算(m是基数, n是指数)
Math.random(n)        // 产生0和1之间的随机小数
Math.round()          // 对n的小数位进行四舍五入
Math.sin(n)           // 计算n的正弦三角函数
Math.sqrt(n)          // 计算n的平方根

 

JaScript中的常用对象

标签:

原文地址:http://www.cnblogs.com/happyfreelife/p/4248305.html

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