gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:28:11 24 4
gpt4 key购买 nike

我尝试使用 <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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com