ie8下-indexOf 和 trim()方法bug

本文探讨了在IE8浏览器下遇到的兼容性问题,包括object.trim()和indexOf()方法不被支持的情况,并提供了相应的解决方案。对于object.trim(),可以通过jQuery的$.trim()替代;对于indexOf(),则推荐使用jQuery的$.inArray()方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

var fileType = $.trim(n.resourcesMapping.extension).toLowerCase();
if($.inArray(fileType,fileTypeList)=='-1'){//其他
	 row.find(".fileType").addClass('other');
}else{
	  row.find(".fileType").addClass(fileType);
}

 ie8真是各种吐槽无能

 

1.不识别object.trim();方法

 

解决方法:$.trim(object);

 

2.ie9以下没有indexOf()这个方法

IE<9 doesn't have an .indexOf() function for Array,

 

解决方案:如果使用jquery的话,可以使用$.inArray()方法

jQuery.inArray()

jQuery.inArray( value, array [, fromIndex ] )Returns: Number
 
Search for a specified value within an array and return its index (or -1 if not found).

 在数组中搜索匹配特殊字符,返回为该字符所在数组中的索引值

jQuery.inArray( value, array [, fromIndex ] )
value
Type: Anything
The value to search for.
array
Type: Array
An array through which to search.
fromIndex
Type: Number
The index of the array at which to begin the search. The default is 0, which will search the whole array.

 

PS:注意

 

The $.inArray() method is similar to JavaScript's native .indexOf() method in that it returns -1 when it doesn't find a match. If the first element within the array matches value, $.inArray() returns 0.

 

 Because JavaScript treats 0 as loosely equal to false (i.e. 0 == false, but 0 !== false), if we're checking for the presence ofvalue within array, we need to check if it's not equal to (or greater than) -1. 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值