【发布时间】:2012-11-06 22:45:00
【问题描述】:
我在上传时使用这个 javascript 来限制文件类型的扩展名:
function TestFileType( fileName, fileTypes ) {
if (!fileName) return;
dots = fileName.split(".")
//get the part AFTER the LAST period.
fileType = "." + dots[dots.length-1];
return (fileTypes.join(".").indexOf(fileType) != -1) ?
alert('Correct File Type Function Here') :
alert('Wrong File Type Function Here');
}
与
<input name="replay_file" id="replay_file" type="file"/>
<input type="submit" id="upload_file" value="Upload" name="uploadReplay" onClick="TestFileType(this.form.replay_file.value, ['w3g','.w3g']);" />
我希望它发出警报(错误的文件类型)然后重新加载页面(这样它会取消上传而不是浪费时间)但到目前为止我只能让警报框工作但不能让页面重新加载功能之后也就是说,页面重新加载不起作用我什至尝试了 goto url 和 windows 位置,但它不起作用,只会在警告框后继续上传文件:
return (fileTypes.join(".").indexOf(fileType) != -1) ?
null() :
alert('Warcraft III replay file (.w3g) allowed only!');window.location.reload();
}
我是否遗漏了什么,或者在文件上传时它不会以这种方式工作?
【问题讨论】:
标签: javascript html upload reload