javascript的一些在IE下不支持的函数小结
// ============ isArray ===============//
// isArray
function isArray(value){
return Object.prototype.toString.call(value) == "[object Array]";
}
var arr = [1,2,3,4,5];
alert(isArray(arr)); // IE8 及以下不支持
// ============ filter 等 ===============//
// 数组的一些方法 every(), filter(), forEach(), map(), some()
// IE8 及以下不支持
// 解决办法,以filter为例,自己写一个filter
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp*/){
var len = this.length;
if (typeof fun != "function"){
throw new TypeError();
}
var res = new Array();
var thisp = arguments[1];
for (var i = 0; i < len; i++){
if (i in this){
var val = this[i]; // in case fun mutates this
if (fun.call(thisp, val, i, this)) {
res.push(val);
}
}
}
return res;
};
} var numbers = [1,2,3,4,5,6];
var filterResult = numbers.filter(function(item, inde, array){
return (item>2);
});
alert(filterResult); // 3,4,5,6
// ============ Date.now() ===============//
// Date.now(); IE8及以下不支持,只能自己写一个解决
if(!Date.now){
Date.now = function(){
return new Date().valueOf();
}
}
alert(Date.now());
// ============ stringValue[1] ===============//
// 在IE7 及以下版本显示 undefined
var stringValue = "hello world";
alert(stringValue[1]);
// ============ trim() ===============//
// 在IE8 及以下版本无效,需要自己写
String.prototype.trim = function(){
return this.replace(/(^\s*)(\s*$)/g, "");
};
var stringValue2 = " hello world ";
alert(stringValue2.trim());
javascript的一些在IE下不支持的函数小结的更多相关文章
- Linux 多线程环境下 进程线程终止函数小结(转)
pthread_kill: pthread_kill与kill有区别,是向线程发送signal.,大部分signal的默认动作是终止进程的运行,所以,我们才要用signal()去抓信号并加上处理函数. ...
- 使用javascript实现html页面直接下载网盘文件
公司新建一网站,用的是商派的易开店系统.设计方案中有一个是下载文件的功能,但易开店不支持上传资源,所以无法下载本站资源. 于是想到了网盘资源下载,有些网站是把页面链接到网盘资源文件下载页面,进行二次跳 ...
- JavaScript 定义类的最佳写法——完整支持面向对象(封装、继承、多态),兼容所有浏览器,支持用JSDuck生成文档
作者: zyl910 [TOC] 一.缘由 由于在ES6之前,JavaScript中没有定义类(class)语法.导致大家用各种五花八门的办法来定义类,代码风格不统一.而且对于模拟面向对象的三大支柱& ...
- max-height,min-height在IE下不支持的解决方法
max-height,min-height在IE下不支持的解决方法 max-width:160px; max-height:160px; _width:expression(this.width &g ...
- Javascript检测浏览器对CSS属性的支持 /* supports */
//检测浏览器对CSS属性的支持 supports = (function() { var div = document.createElement('div'), vendors = 'Khtml ...
- javascript实现可编辑的下拉框
曾经遇到过一个需求的情况是这样的,我们提供给用户的输入框的可选择项只能满足用户的大部分情况的选择,但是有时候会遇到一些用户想要输入的数据是下拉项中所没有的,而用户不希望改变下拉项为输入框模式,需要说如 ...
- windows Apache 环境下配置支持HTTPS的SSL证书
windows Apache 环境下配置支持HTTPS的SSL证书 1.准备工作 1)在设置Apache + SSL之前, 需要做: 安装Apache, 下载安装Apache时请下载带有SSL版本的A ...
- Mac系统下编译支持Android平台的最新X264编码器
Mac系统下编译支持Android平台的最新X264编码器 原文来自 http://www.mingjianhua.com,转载请注明出处 1.首先去官网下载最新的x264源代码,解压到任意目录 ht ...
- centos7.3下curl支持https协议
1 由于自己的curl是默认安装的,查看了下 不支持https协议 [root@izwz90bp6do7s3cr45cw6az ~]# curl --version curl (x86_64-redh ...
随机推荐
- byte处理的几种方法
/** * 字符串转16进制byte * @param * @return * @throws Exception * @author hw * @date 2018/10/19 9:47 */ pr ...
- golang语言调试
https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs https: ...
- 下载google play上最新版的apk
注意,是下载最新版的方法,不是像很多网站下的是旧版本 http://techapple.net/2014/09/3-websites-directly-download-apk-google-play ...
- PHP消息队列实现及应用_慕课网学习
https://blog.csdn.net/d_g_h/article/details/79643714 https://blog.csdn.net/tTU1EvLDeLFq5btqiK/articl ...
- Scala里面如何使用枚举
枚举通常用来定义已知数量的常量,比如月份,星期,季节等等,用过java的人都知道定义枚举的关键字是enum,在scala里面和java有所不同,来看一个完整的例子定义: object EnumTest ...
- [LeetCode] 383. Ransom Note_Easy tag: Hash Table
Given an arbitrary ransom note string and another string containing letters from all the magazines, ...
- vscode 搭建react-native
vscode 搭建react-native 选择:vscode + typings + eslint * vscode: 宇宙最强IDE家族的最新产品 * typings: 基于typescirpt的 ...
- Quick Look at the Air Jordan 32
A color with 25 years of history in the Air Jordan line will once again leave its mark on the Air Jo ...
- Android View事件分发源码分析
引言 上一篇文章我们介绍了View的事件分发机制,今天我们从源码的角度来学习下事件分发机制. Activity对点击事件的分发过程 事件最先传递给当前Activity,由Activity的dispat ...
- Javascript-逻辑运算符非(!)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...