【问题标题】:Remove font tags from htmlText从 htmlText 中删除字体标签
【发布时间】:2012-01-16 13:00:21
【问题描述】:

我想从 TextField 生成的 htmlText 字符串中删除字体标签,使周围的节点和任何粗体等标签保持不变。

htmlText的部分输出示例:

<P ALIGN="LEFT"><FONT FACE="ChampagneLimo" SIZE="18" COLOR="#000000" LETTERSPACING="0" KERNING="0">Lorem Ipsum</FONT></P>

我的计划是避免尝试使用正则表达式并创建一个 XML 对象。

但是,如果我创建一个包含根节点的新 XML 对象,然后尝试 appendChild htmlText 字符串,以便我有一个有效的 XML 对象来操作我遇到了 html 实体问题,请参见下面的示例:

<html>&lt;P ALIGN="LEFT"&gt;&lt;FONT FACE="...

如何从 htmlText 中去除字体标签以及如何从 htmlText 字符串创建有效的 XML 对象?我的计划是使用 XML replace() 方法,但我愿意接受建议。

【问题讨论】:

    标签: html xml flash actionscript-3


    【解决方案1】:

    只需将&lt;html&gt; 标记添加到字符串中,而不是创建额外的节点:

    var xml : XML = new XML ("<html>"+ myTextField.htmlText + "</html>");
    

    您也可以使用正则表达式来删除字体标签:

    var reg:RegExp = /\<\/?FONT.*?\/?\>/gi; 
    // matches all <FONT> start and end tags 
    // (case-insensitive), along with any attributes 
    var myHtmlText:String = myTextField.htmlText.replace (reg, "");
    

    【讨论】:

      猜你喜欢
      • 2014-03-01
      • 1970-01-01
      • 2020-02-13
      • 1970-01-01
      • 1970-01-01
      • 2014-05-27
      • 2018-10-31
      • 2012-01-21
      • 2023-03-23
      相关资源
      最近更新 更多