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.