【问题标题】:Move cursor inside textarea to end在文本区域内移动光标到结束
【发布时间】:2011-09-19 20:59:46
【问题描述】:

我在应该接受 5 位美国邮政编码的表单上有一个文本区域控件。我已经为控件分配了一个 keyUp 事件,该事件检查输入的字符数,直到达到 5,然后强制换行。

public function forceNewLine(event:KeyboardEvent):void
{
    var maxLineChars:int = 5;
    var currentLine:int = 1;
    var numChars:int;

    numChars = (txtList.text.length);
    currentLine = Math.round(txtList.text.length / 6);

    if (numChars == (maxLineChars * currentLine))
    {
        txtList.text = txtList.text + "\n";
        txtList.setCursorPosition() 
        //This is not a function I have defined but I think I need too..
    }
}

<s:TextArea id="txtList" keyUp="forceNewLine(event)"/>

除了插入新行时,光标移动到文本区域的开头之外,它工作正常。我希望它走到最后。

【问题讨论】:

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


    【解决方案1】:

    尝试使用 spark textArea 的 selectRange 函数。

    txtList.selectRange(txtList.text.length, txtList.text.length)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-05
      • 2012-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-12
      相关资源
      最近更新 更多