XHTML Strict 1.0 页面的 Enctype
为了我自己的启发,我构建了一个包含表单的 XHTML Strict 1.0 页面。我希望它只接受 text/xml MIME 类型,因此我相应地指定了 accept 属性。 但是,当还包含 enctype="mulipart/form-data" 属性值对时,无法对其进行验证。
使用 XHTML Strict 1.0 时是否有指定 enctype 的替代方法?我需要指定 enctype 或类似的东西吗?
我还没有设置实际的“操作”(cgi 或其他一些后端函数)。我目前只关心客户端,并希望在上传任何非 xml 内容时提示用户。我这里需要 JavaScript 吗?
而且,似乎没有太多人喜欢任何形式的 XHTML。如果您可以自由地为静态页面选择 XHTML Strict/Frameset/Transitional 或 HTML 4.01,哪个标准最好?
I have, for my own edification, constructed an XHTML Strict 1.0 page containing a form. I'd like for it to accept text/xml MIME-types only and so I've specified the accept attribute accordingly. However, it can't be validated when also including the enctype="mulipart/form-data" attribute-value pair.
Is there an alternative to specifying the enctype when working with XHTML Strict 1.0? Do I need to specify the enctype or something similar at all?
I have not set up an actual "action" (cgi or some other back-end function). I'm only concerned with client-side for the moment and would like for the user to be prompted when uploading anything that's NOT xml. Do I need JavaScript here?
Also, it seems that not too many people are fond of XHTML in any form. If you have the liberty of choosing XHTML Strict/Frameset/Transitional or HTML 4.01 for a static page, which standard would be best?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
表单编码(enctype 属性)必须为
multipart/form-data
才能使文件上传正常工作。据我所知,
accept
属性根本没有在任何浏览器中实现。因此,如果您想在实际上传之前提供有关所选文件的任何反馈,那么使用 Javascript 似乎是唯一的选择。
有些人对 XHTML 有非常强烈的看法,但这并不意味着它不是一个广泛使用的标准。
The form encoding (enctype attribute) has to be
multipart/form-data
for the file uploads to work.According to what I can find, the
accept
attribute is not implemented in any browser at all.So, using Javascript seems like the only option if you want to offer any feedback on the selected file before the actual upload.
There are some people that have very strong opinions about XHTML, but that doesn't mean that it's not a widely used standard.
首先解决最后一点:严格的 XHTML 1.1 受到以下事实的困扰:W3C 建议确实要求您将文档作为 MIME 类型
application/xml+xhtml
或类似的类型提供,而这实际上是不可能的以满足大多数(如果不是全部)当前客户的方式在 Web 服务器上进行设置。因此,如果您无论如何都做不好,您不妨使用 HTML 4.01,它在语法上几乎等效,并且可以说更强大(例如,HTML 4.01 可以有效地禁止嵌套锚点,而 XHTML 必须将其添加为文本额外子句)。您将完成相同的工作,并且几乎所有现有客户实际上都会理解它。 (因为我相信您只会使用 DOM 方法来操作客户端文档,所以 AJAX 后端发送其他形式的 XML 也不会有问题。)对于第一个问题:没有什么可以强制任何客户做任何特定的事情。
accept
属性是对客户端的提示,您的服务器可能会接受或拒绝,但它不必以任何定义的方式对此进行操作。如果您愿意,您可以使用脚本在客户端上添加一些可选的附加验证,但当然您也始终必须验证服务器上的输入数据。To address the last point first: Strict XHTML 1.1 suffers from the fact that the W3C recommendation really requires you to deliver the document as MIME type
application/xml+xhtml
or something like that, and that's virtually impossible to set up on a web server in a way that satisfies most, if not all, current clients. So if you cannot do it right anyway you might as well just use HTML 4.01, which is grammatically nearly equivalent and arguably more powerful (e.g. HTML 4.01 can validably prohibit nested anchors, while XHTML has to add that as a textual extra clause). You'll get the same job done, and it'll actually be understood by nearly all existing clients. (Since I trust you'll only be using DOM methods to manipulate the document client-side, there won't be a problem with AJAX backends sending other forms of XML, either.)For the first question: There is nothing that forces any client to do anything specific. The
accept
attribute is a hint for the client what your server will probably accept or reject, but it doesn't have to act on this in any defined manner. If you like, you can add some optional additional verification on the client with scripting, but of course you always must validate input data on the server, too.