gpt4 book ai didi

xhtml - 可以在文本区域字段中添加换行符同时保持 XHTML 1.0 有效吗?

转载 作者:行者123 更新时间:2023-12-01 09:02:52 24 4
gpt4 key购买 nike

编辑: 重新阅读我的帖子后,我觉得我有点不清楚问题出在哪里。让我尝试重新措辞:

用户可以使用表单中的文本区域字段在我的网站上发表评论。应该可以使用 <br /> 在评论中添加换行符.然后将评论作为字符串存储在 mysql 数据库中(进行转义以确保安全),然后从数据库中检索并显示在站点上。显示评论时无法识别常规换行符。

用户可以编辑他们的评论,在这种情况下,原始评论会显示在要修改的文本区域中(见下图)。问题是如果有任何 <br />目前,该代码作为 XHTML 1.0 无效(请参阅下面的错误消息)。

我可以使用任何其他类型的换行符使代码有效吗?如评论中所述,常规换行符与 xml:space="preserve"组合不起作用(换行符显示在 textarea 字段中,但当评论在网站上显示为普通文本时则不会)。


原始问题:

我有一个网络表单,其中包含一个用于发表评论的文本区域,我希望它能够使用 <br /> 添加换行符.下面是一个简单的例子:

screen dump
(来源:shipit.se)

它按预期工作,但是在使用 W3C 验证服务时它不会验证为 XHTML 1.0 过渡版。这是我得到的错误:

  1. Error Line 90, Column 1587: document type does not allow element "br" here

…ription" rows="0" cols="0">Test<br />line break</textarea></dd><dt class="cha

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).

有没有办法使换行符有效代码,或者我是否需要找到解决方法(例如,在 textarea 字段中使用特定标记作为换行符,然后在稍后显示评论时用 <br /> 替换它们)?

最佳答案

您是否尝试过添加 xml:space="preserve" 属性并仅使用普通的普通换行符?

关于xhtml - 可以在文本区域字段中添加换行符同时保持 XHTML 1.0 有效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/755944/

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