【问题标题】:Insert text in RichTextEditor on cursor position在光标位置在 RichTextEditor 中插入文本
【发布时间】:2012-01-12 14:28:38
【问题描述】:

当用户单击按钮时,我会在富文本编辑器上插入日期。 这部分很简单,更难的是如何在光标位置插入它。光标位置可以在文本的开头、中间或结尾。

感谢您的帮助

【问题讨论】:

    标签: actionscript-3 apache-flex flash-builder


    【解决方案1】:

    就这么简单:

        protected function richText_keyDownHandler(event:KeyboardEvent):void
        {
            if (event.keyCode == 66) //or remove if statement
                richText.insertText("Really?");
        }
    
    
        <s:RichEditableText id="richText" text="Lorem ipsum dolor sit amet"   
    keyDown="richText_keyDownHandler(event)"/>
    

    编辑: for mx RichTextEditor

            protected function richText_keyDownHandler(event:KeyboardEvent):void
            {
                var ind:int = richEdit.selection.beginIndex;
                richEdit.text = richEdit.text.substring(0, ind) +   
                "Your text variable here" +   
                richEdit.text.substring(ind, richEdit.text.length);     
            }
    

    和mx富文本编辑器:

        <mx:RichTextEditor id="richEdit" text="Lorem ipsum dolor sit amet"  
     keyDown="richText_keyDownHandler(event)"/>
    

    也许有更有效的方法,但这是我唯一能想到的。

    【讨论】:

    • 谢谢,但
    • 这种方法存在一个问题。如果用户在编辑器中进行了任何格式化(例如使文本变为粗体或斜体),则在此事件之后,该格式化就会消失。有谁知道如何解决这个问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-09
    • 2013-08-03
    • 2016-08-01
    相关资源
    最近更新 更多