Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The below function works fine on Opera, Firefox and Chrome.(以下功能在Opera,Firefox和Chrome上正常运行。)

However, in IE8 it fails on the if ( allowed.indexOf(ext[1]) == -1) part.(但是,在IE8中,它在if ( allowed.indexOf(ext[1]) == -1)部分失败。) Does anyone know why?(有人知道为什么吗?) Is there any obvious mistake?(有没有明显的错误?) function CheckMe() { var allowed = new Array('docx','xls','xlsx', 'mp3', 'mp4', '3gp', 'sis', 'sisx', 'mp3', 'wav', 'mid', 'amr', 'jpg', 'gif', 'png', 'jpeg', 'txt', 'pdf', 'doc', 'rtf', 'thm', 'rar', 'zip', 'htm', 'html', 'css', 'swf', 'jar', 'nth', 'aac', 'cab', 'wgz'); var fileinput=document.getElementById('f'); var ext = fileinput.value.toLowerCase().split('.'); if ( allowed.indexOf(ext[1]) == -1) { document.getElementById('uploadsec').innerHTML = document.getElementById('uploadsec').innerHTML; alert('This file type is not allowed!'); } }   ask by nLL translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
177 views
Welcome To Ask or Share your Answers For Others

1 Answer

Versions of IE before IE9 don't have an .indexOf() function for Array, to define the exact spec version , run this before trying to use it:(IE9之前的IE版本没有用于Array的.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; }; } This is the version from MDN , used in Firefox/SpiderMonkey.(这是MDN的版本,在Firefox / SpiderMonkey中使用。) In other cases such as IE, it'll add .indexOf() in the case it's missing... basically IE8 or below at this point.(在其他情况下,例如IE,它会在丢失的情况下添加.indexOf() ...此时基本上是IE8或更低版本。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...