在选择的时候就做出判断,不是选择后提交时去判断,各位知道这个怎么解决吗。我只知道点击上传时去判断,附上点击是判断的语句,请问在哪加条件才能实现在选择时就加以判断:
<html>
<head>
<SCRIPT type="text/JavaScript">
function LimitAttach(form, file) {
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
if (".xls" == ext)
form.submit();
else
alert("对不起,只能上传以下格式的文件: "
+ ".xls" + "\n请重新选择符合条件的文件"
+ "再上传.");
}
</script>
</head>
<body>
<p>
<form method=post name=upform action="http://www.sharejs.com" >
<input type=file id="select" name=uploadfile>
<p>
<input type=button name="Submit" value="Submit" onclick="LimitAttach(this.form, this.form.uploadfile.value)">
</form>
</body>
</html>
<html>
<head>
<SCRIPT type="text/JavaScript">
function LimitAttach(form, file) {
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
if (".xls" == ext)
form.submit();
else
alert("对不起,只能上传以下格式的文件: "
+ ".xls" + "\n请重新选择符合条件的文件"
+ "再上传.");
}
</script>
</head>
<body>
<p>
<form method=post name=upform action="http://www.sharejs.com" >
<input type=file id="select" name=uploadfile>
<p>
<input type=button name="Submit" value="Submit" onclick="LimitAttach(this.form, this.form.uploadfile.value)">
</form>
</body>
</html>
var fileName = document.getElementById("select").value;
alert(fileName);
}
我要实现的功能是点击浏览,弹出的选择框中不是有文件类型的选择吗(如:所有文件(*.*) 图片 *.jpg等),我要实现的就是弹出后 相当于文件类型默认为.xls,弹出框中就只有.xls这一类型的文件可以让我选择,请问有没有方法实现
你看下这个哦,可以控制上传文件类型的.