前端 文件上传限制条件

<html>
<head>
<meta charset="utf-8">
<title>JS检查文件后缀</title>
</head>
<body>

<script type="text/javascript">
function selectFile(fnUpload) {
var filename = fnUpload.value;
var mime = filename.toLowerCase().substr(filename.lastIndexOf("."));
if(mime!=".jpg")
{
alert("请选择jpg格式的照片上传");
fnUpload.outerHTML=fnUpload.outerHTML;
}
}
</script>

<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" onchange="selectFile(this)" />
<br />
<input type="submit" name="submit" value="submit" />
</form>

</body>
</html>

posted on 2021-06-24 21:33  吉晨  阅读(184)  评论(0编辑  收藏  举报

导航