为什么单个textarea会把所有的xhtml弄得一团糟? [英] Why single textarea mess all following xhtml?

查看:104
本文介绍了为什么单个textarea会把所有的xhtml弄得一团糟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络程序遇到问题.我的表单中有一个textarea,有时textarea中没有任何内容,因此genshi模板引擎只是将其输出为

<textarea xxxx />

,问题来了,以下所有标记都在文本区域中.为什么所有浏览器都不能正确处理单个文本区域?

如果我将其写为

<textarea xxxx></textarea>

,一切正常.为什么单个textarea会混淆xhtml中的以下标记?

解决方案

因为您大概正在为XHTML提供text/html Content-type并将其处理为HTML. XML样式的自动关闭标签在HTML中不存在(因此,您必须使用显式的开始和结束标签,除非它们被禁止(例如img上的结束标签)或可选(例如body元素上的开始和结束标签)./p>

如果您希望将页面处理为XHTML,则可以用作application/xhtml + xml(并告别以从Internet Explorer支持).

(这就是为什么我在大多数项目中都坚持使用HTML 4.01的原因)

请参见> http://www.w3.org/TR/xhtml-media -types/获取更多详细信息(包括完整的兼容性准则,以将您的XHTML调整为HTML用户代理可以应对的形状).

I encounter a problem in my web program. I got a textarea in my form, sometimes there is nothing in textarea, so genshi template engine just output it as

<textarea xxxx />

and here comes the problem, all following tags are in the textarea. Why all browser can't handle single textarea correctly?

If I write it as

<textarea xxxx></textarea>

and everything works fine. Why a single textarea messes following tags in xhtml?

解决方案

Because you are, presumably, serving your XHTML with a text/html Content-type and causing it to be processed as HTML. XML style self-closing tags do not exist in HTML (so you have to use explicit start and end tags, except where they are forbidden (e.g. end tags on img) or optional (e.g. start and end tags on the body element).

If you want to have your pages processed as XHTML then serve as application/xhtml+xml (and kiss goodbye to support from Internet Explorer).

(This is why I stick to HTML 4.01 for most projects)

See http://www.w3.org/TR/xhtml-media-types/ for more details (including the full set of compatibility guidelines to munge your XHTML into a shape where HTML user agents can cope with it).

这篇关于为什么单个textarea会把所有的xhtml弄得一团糟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆