文本字段中的 ActionScript 3.0 换行符
TextField 可以包含不同类型的换行符吗?
我将输入字段中的文本保存并加载到 XML 中。我将其保存为 CDATA 标签,包括换行符。
发生的情况如下:
- 我在文本字段中输入带有换行符的文本
- 我将文本保存到 XML
- 我清空文本字段
- 我将 xml 加载到文本字段中 - 一切看起来都符合预期,存在换行符
- 我再次保存完全相同的文本字段(唯一的区别是这次内容已加载,而不是手写)
- 这次,当我再次加载 XML 时,它不包含任何换行符
- ,文本没有换行符,
这是怎么回事?
//这是一个演示该问题的示例:
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:
- I type a text with linebreaks into the textfield
- I save the text to the XML
- I empty the textfield
- I load the xml into the textfield - everything looks as expected, linebreaks are present
- I save the exact same textfield again (the only difference this time the content was loaded and not handtyped)
- This time the XML does not contain any linebreaks
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试对您的文本值进行编码
Try encoding your text value