在文件上传中使用 accept 属性,本例中的输入字段可以接受任意格式的图像:
<form>
<input type="file" name="pic" id="pic" accept="image/*" />
</form>
运行效果:
如果限制图像格式,如只允许 GIF 和 JPEG 两种图像,则accept可写为:
accept="image/gif, image/jpeg"
在文件上传中使用 accept 属性,本例中的输入字段可以接受任意格式的图像:
<form>
<input type="file" name="pic" id="pic" accept="image/*" />
</form>
运行效果:
如果限制图像格式,如只允许 GIF 和 JPEG 两种图像,则accept可写为:
accept="image/gif, image/jpeg"