在项目中有些时候需要进行文件的上传,这时候在前端页面可以使用 标签的 accept 属性,定义和用法
accept 属性只能与 配合使用。它规定能够通过文件上传进行提交的文件类型。
<input accept="value">
比如:输入字段可以接受 gif和 jpeg 两种图像
<form>
<input type="file" name="pic" id="pic" accept="image/gif, image/jpeg" />
</form>
如果不限制图像的格式,可以写为:accept=“image/*”。
比如:
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp">
<input type="file" name="pic" accept="image/*">
<input type="submit">
</form>
</body>
</html>