练习JavaScript判断上传文件后缀名
<script type = text/javascript>
function jiance(filename)
{
var pic = ["jpg","png","gif"];
var indx = filename.lastIndexOf(".");
var ext = filename.substr(indx+1);
for (var a = 0;a < pic.length; a++ )
{
if (ext == pic[a])
{
document.write("文件名合法");
break;
}else
{
document.write("文件不合法");
break;
}
}
}
</script>
</head>
<body>
<from method = "post" enctype = "multipart/form-data">
上传图片<input type = "file" name = "uploadfile" onchange = "jiance(this.value)">
</from>
</body>
</html>
function jiance(filename)
{
var pic = ["jpg","png","gif"];
var indx = filename.lastIndexOf(".");
var ext = filename.substr(indx+1);
for (var a = 0;a < pic.length; a++ )
{
if (ext == pic[a])
{
document.write("文件名合法");
break;
}else
{
document.write("文件不合法");
break;
}
}
}
</script>
</head>
<body>
<from method = "post" enctype = "multipart/form-data">
上传图片<input type = "file" name = "uploadfile" onchange = "jiance(this.value)">
</from>
</body>
</html>
后来都会美好的!