ECMAScript 引用类型

Global对象 全局的、终极的、兜底的对象(不存在的) 所有在全局作用域内定义的属性和方法,都是Global对象的属性
常用的几个方法:encodeURI 、encodeURIComponent、decodeURI 、decodeURIComponent、escape、unescape 、eval、parseInt、parseFloat、isNaN

uri编码
encodeURI 、
encodeURIComponent、
以上方法用于对URI(通用资源标识符)进行编码,以便发送给浏览器。浏览器不能理解和接收一些特殊字符,比如:空格,所以这两个方法用UTF-8编码替换URI中的无效字符以使浏览器能够识别。
encodeURI(): 主要用于整个URI,不会对本身属于URI的特殊字符进行编码,如冒号,正斜杠、问号、井号
encodeURIComponent() : 任何不标准的字符都会进行转码,常用

uri解码:
decodeURI 、
decodeURIComponent、

示例:

//encodeURI 、encodeURIComponent
var uri = 'http://www.baidu.com cn';
var str1 = encodeURI(uri);       //://不会进行转码
var str2 = encodeURIComponent(uri);     //任何不标准的字符都会进行转码,常用
alert(str1);                //http://www.baidu.com%20cn
alert(str2);                //http%3A%2F%2Fwww.baidu.com%20cn
//decodeURI 、decodeURIComponent
alert(decodeURI(str1));         //http://www.baidu.com cn
alert(decodeURIComponent(str2));    //http://www.baidu.com cn

escape unescape 对中文进行转码、解码
var str1 = “一眼万年”;
alert(escape(str1)); //%u4E00%u773C%u4E07%u5E74
alert(unescape(escape(str1))); //一眼万年

eval 类似无形的JavaScript解析器

var str1 = "var a = 10; var b = 20;";
eval(str1);     //传入字符串
alert(a+b);

//字符串对象  
var str = "{name:'z3',age:20}";
var obj = eval("("+str+")");          //将字符串转换为对象
alert(obj.name);

parseInt、parseFloat

var num1 = parseInt("5");
var num2 = parseFloat("12.6");
alert(num1 + "||"+num2);            // 5   12.6
alert(typeof num1);         //number
alert(typeof num2);         //number

isNaN是否不是一个数:不是number为true,是number为false.
在JS里面只有NaN不等于自己本身

var num1 = "10";
var num2 = "abc"
alert(isNaN(num1));     //false
alert(isNaN(num2));     //true

Date日期类型

var date = new Date();
alert(date);
//获取年
alert(date.getFullYear());
//获取月份
alert(date.getMonth()+1);
//获取日期
alert(date.getDate());
//获取时
alert(date.getHours())
//获取分
alert(date.getMinutes());
//获取秒
alert(date.getSeconds())
//星期
alert(date.getDay());
//获取当前时间的毫秒数
alert(date.getTime());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值