文本字段中的 ActionScript 3.0 换行符

发布于 2024-12-17 14:45:44 字数 1071 浏览 1 评论 0原文

TextField 可以包含不同类型的换行符吗?

我将输入字段中的文本保存并加载到 XML 中。我将其保存为 CDATA 标签,包括换行符。

发生的情况如下:

  1. 我在文本字段中输入带有换行符的文本
  2. 我将文本保存到 XML
  3. 我清空文本字段
  4. 我将 xml 加载到文本字段中 - 一切看起来都符合预期,存在换行符
  5. 我再次保存完全相同的文本字段(唯一的区别是这次内容已加载,而不是手写)
  6. 这次,当我再次加载 XML 时,它不包含任何换行符
  7. ,文本没有换行符,

这是怎么回事?

//这是一个演示该问题的示例:

var xml1 = <xml>
               <elm/>
           </xml>;

xml1.elm.text = new XML("<![CDATA[" + textField.text + "]]>");

trace(xml1);

textField.text="";
textField.appendText(xml1.elm.text());

var xml2 = <xml>
               <elm/>
           </xml>;

xml2.elm.text = new XML("<![CDATA[" + textField.text + "]]>");

trace(xml2);

我在文本字段中输入了

以下 文本 换行

并在其上运行代码。尽管文本字段之后看起来仍然很好(显示换行符),但代码的输出显示:

<xml>
  <elm><![CDATA[this is
a linebreak]]></elm>
</xml>
<xml>
  <elm><![CDATA[this isa linebreak]]></elm>
</xml>

那怎么可能?

Can a TextField can contain different kinds of linebreaks?

I save and load text from an input field into an XML. I save it as CDATA tags including linebreaks.

This is what happens:

  1. I type a text with linebreaks into the textfield
  2. I save the text to the XML
  3. I empty the textfield
  4. I load the xml into the textfield - everything looks as expected, linebreaks are present
  5. I save the exact same textfield again (the only difference this time the content was loaded and not handtyped)
  6. This time the XML does not contain any linebreaks
  7. when I load it again, the text doesn't have linebreaks

How can this be?

//here is an example that demonstrates the issue:

var xml1 = <xml>
               <elm/>
           </xml>;

xml1.elm.text = new XML("<![CDATA[" + textField.text + "]]>");

trace(xml1);

textField.text="";
textField.appendText(xml1.elm.text());

var xml2 = <xml>
               <elm/>
           </xml>;

xml2.elm.text = new XML("<![CDATA[" + textField.text + "]]>");

trace(xml2);

I enter into a textField the text

this is
a linebreak

And run the code on it. Although the textfield looks still fine afterwards (displays the linebreak) the output of the code shows:

<xml>
  <elm><![CDATA[this is
a linebreak]]></elm>
</xml>
<xml>
  <elm><![CDATA[this isa linebreak]]></elm>
</xml>

How can that be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘香 2024-12-24 14:45:44

尝试对您的文本值进行编码

xml1.elm.text = new XML("<![CDATA[" + encodeURIComponent(textField.text) + "]]>");

Try encoding your text value

xml1.elm.text = new XML("<![CDATA[" + encodeURIComponent(textField.text) + "]]>");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文