【解决】js中ie8下不识别indexOf的解决办法

把一下代码放在你的indexOf方法的上面:


if (!Array.prototype.indexOf){
  		Array.prototype.indexOf = function(elt /*, from*/){
	    var len = this.length >>> 0;
	    var from = Number(arguments[1]) || 0;
	    from = (from < 0)
	         ? Math.ceil(from)
	         : Math.floor(from);
	    if (from < 0)
	      from += len;
	    for (; from < len; from++)
	    {
	      if (from in this &&
	          this[from] === elt)
	        return from;
	    }
	    return -1;
	  };
	}

js判断是否是图片:


function checkImg(){
		var sLogo = $("#sLogo").val();
		var imgType = ['jpg','gif','png'];
		if(sLogo!=null){
			var subffix = sLogo.substring(sLogo.lastIndexOf('.')+1);
			if(imgType.indexOf(subffix)==-1){
				$("#spSLogo").attr("style","display:block;color:red;");
				return false;
			}else{
				$("#spSLogo").attr("style","display:none");
			}
		}
		
		return true;
	}


你可能感兴趣的:(indexOf不识别,ie8下indexOf)