JS 兼容小积累【置顶】
来源:互联网 发布:华数传媒网络校园招聘 编辑:程序博客网 时间:2024/06/10 03:11
1. //alert( oDiv.getAttribute('class') ); // ie678 以下面找不到class
//alert(oDiv.getAttribute('data-time')); // 自定义绑定的数据是全兼容的
//alert( oDiv.getAttribute('id') ); // 全兼容
oDiv.setAttribute('class','wrap22'); // 全兼容
//oDiv.removeAttribute('class'); // ie678下面class 失去作用
//oDiv.removeAttribute('class');
总结: 问题出现在寻找class的问题上,因此在ie678中使用的时候需要重新写getAttribute,removeAttribute。不兼容ie678则可以完全忽略。
2. 编码问题
// decodeURI()
var str = 'http://www.baidu.com/qiu yan long/list/首页';
//alert( unescape(escape(str)) );
// escape和unescape在es3以后不建议使用,但是还是可以使用,推荐使用encodeURI 和 encodeURLComponent();
var re = encodeURI(str); // 只编码空格跟中文字符串
var rr = encodeURIComponent(str); // 所有的都会进行编码
document.write( re +'<br/>');
//http://www.baidu.com/qiu%20yan%20long/list/%E9%A6%96%E9%A1%B5
document.write( rr +'<br/>');
//http%3A%2F%2Fwww.baidu.com%2Fqiu%20yan%20long%2Flist%2F%E9%A6%96%E9%A1%B5
document.write( decodeURI(re)+'<br/>' );
document.write( decodeURIComponent(rr)+'<br/>' );
//alert(oDiv.getAttribute('data-time')); // 自定义绑定的数据是全兼容的
//alert( oDiv.getAttribute('id') ); // 全兼容
oDiv.setAttribute('class','wrap22'); // 全兼容
//oDiv.removeAttribute('class'); // ie678下面class 失去作用
//oDiv.removeAttribute('class');
总结: 问题出现在寻找class的问题上,因此在ie678中使用的时候需要重新写getAttribute,removeAttribute。不兼容ie678则可以完全忽略。
2. 编码问题
// decodeURI()
var str = 'http://www.baidu.com/qiu yan long/list/首页';
//alert( unescape(escape(str)) );
// escape和unescape在es3以后不建议使用,但是还是可以使用,推荐使用encodeURI 和 encodeURLComponent();
var re = encodeURI(str); // 只编码空格跟中文字符串
var rr = encodeURIComponent(str); // 所有的都会进行编码
document.write( re +'<br/>');
//http://www.baidu.com/qiu%20yan%20long/list/%E9%A6%96%E9%A1%B5
document.write( rr +'<br/>');
//http%3A%2F%2Fwww.baidu.com%2Fqiu%20yan%20long%2Flist%2F%E9%A6%96%E9%A1%B5
document.write( decodeURI(re)+'<br/>' );
document.write( decodeURIComponent(rr)+'<br/>' );
0 0
- JS 兼容小积累【置顶】
- js小常识积累
- js小方法积累
- js小积累
- JS小功能点积累
- Js编程小技巧(不断积累中)
- div+css兼容积累
- 小积累
- 小积累
- 小积累
- [置顶]MVC3小技巧
- JS积累
- JS积累
- JS积累
- js积累
- js积累
- js:积累
- js 积累
- webapp中的单位
- js模块化开发
- Android NDK c创建新的线程
- QPixmap::operator=: Cannot assign to pixmap during painting
- navigator.geolocation API 地理位置
- JS 兼容小积累【置顶】
- flex布局
- call,apply 和 bind 的对比分析
- js 面向对象组件开发
- SecureCRT 不能输入命令及回车键不能用
- 征战Node.js 之路
- ServletActionContext.getRequest().getRealPath(savePath) 有错误
- jquery 模板替换
- 深层次学习jquery的API的装逼写法