Why single textarea mess all following xhtml?

混江龙づ霸主 提交于 2019-12-12 20:01:50

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/1427788/why-single-textarea-mess-all-following-xhtml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!