Internet Explorer是我的开发生活的祸根,拒绝再次做其他浏览器似乎毫不费力地做的事情。我试图清除浏览代码/值,如果用户选择一个不允许的文件类型。适用于FF但不适用IE 9.谢谢IE中没有清除框的问题
<script type="text/javascript">
<!--
extArray = new Array(".jpg", ".png");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) {
allowSubmit = true;
break;
}
}
if (allowSubmit) {
return true;
} else {
alert("Please only upload files that end in types: "
+ (extArray.join(" ")) + "\nPlease select a new "
+ "file to upload and submit again.");
document.getElementById('photobrowser').value = "";
return false;
}
}
-->
</script>
<form action="process.php" method="POST" enctype="multipart/form-data" name="formUpload">
<label>Picture:</label>
<input type="file" name="photo" id="photobrowser" onchange="return LimitAttach(formUpload, formUpload.photo.value)" tabindex="4">
<input type="hidden" name="subphoto" value="<?php echo $newCount ?>" />
<input type="image" src="styling/images/button-add-photo.png" id="subBtn" tabindex="6" />
</form
我有进一步的验证,这只是为了加快文件选择,但谢谢你的抬头。 – user29660