html - 如果输入接受属性包含 MIME 类型列表,则 W3C 验证错误

标签 html validation file-upload

我尝试使用 <input type="file" ...> 的接受属性元素将文件打开对话框限制为 RTF 文件。 Internet 资源表明该属性可以包含以逗号分隔的扩展名和 MIME 类型列表。它确实有效,但存在验证问题:

此 HTML5 代码

<!DOCTYPE html>
<html>
  <meta charset="utf-8" />
  <title>Test</title>
</head>
<body>

<form>
  <input type="file" accept=".rtf, text/rtf, application/rtf, text/richtext" />
  <input type="submit"/>
</form>

</body>
</html>

导致此错误 HTML5 validator :

Bad value .rtf, text/rtf, application/rtf, text/richtext for attribute accept on element input: Expected a token character or / but saw , instead.

这是 W3C 验证器的实验性 HTML5 一致性检查器中的错误吗?

最佳答案

来自spec ,

The accept attribute may be specified to provide user agents with a hint of what file types will be accepted.

If specified, the attribute must consist of a set of comma-separated tokens, each of which must be an ASCII case-insensitive match for one of the following:

  • The string audio/*
    Indicates that sound files are accepted.
  • The string video/*
    Indicates that video files are accepted.
  • The string image/*
    Indicates that image files are accepted.
  • A valid MIME type with no parameters
    Indicates that files of the specified type are accepted.
  • A string whose first character is a "." (U+002E) character
    Indicates that files with the specified file extension are accepted.

我已经尝试过验证器,并且

  • <input type="file" accept="text/rtf, application/rtf, text/richtext" />验证。
  • <input type="file" accept=".rtf" />未验证。

所以问题是.rtf ,应该被接受,因为它属于最后一类允许的 token 。

此外,规范提供了这个示例,但无法验证

<input type="file" accept=".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document">

那么,这是验证器的问题。

关于html - 如果输入接受属性包含 MIME 类型列表,则 W3C 验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25391613/

相关文章:

c++ - 分段FTP上传

java - ServletFileUpload.parseRequest() 为 MockMultipartHttpServletRequest 返回一个空列表

flutter - 如何在 Flutter 中将图像上传到服务器?

javascript - 无法加载资源:net::ERR_CONTENT_LENGTH_MISMATCH(PHP错误)

javascript - Raspberry Pi 的 PHP/HTML 通信

RAML 文件的验证

c# - 验证您的网站

html - 图像顶部带有文本的滑动响应图像

java - 如何在 thymeleaf 中使用 math.max 来查找最大数字?

c - 处理此错误检查的正确方法是什么?