当前位置: 代码迷 >> Web前端 >> TextArea在光标处安插字符串
  详细解决方案

TextArea在光标处安插字符串

热度:104   发布时间:2012-11-01 11:11:32.0
TextArea在光标处插入字符串

<?xml version="1.0" encoding="utf-8"?>
<!--?@author?magicianzrh?????????-->
<!--?@ignore?www.actionscript3.cn/magicianzrh?-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
?<mx:Script>
??<![CDATA[
???
???[Bindable]
???private var textAreaString:String = "textAreaString";
???[Bindable]
???private var insertString:String = "|insert|";
???
???private function insertHandler():void {
????if (textArea.selectionBeginIndex == textArea.selectionEndIndex) {
?????var startPart:String = textAreaString.substring(0,textArea.selectionBeginIndex);
?????var endPart:String = textAreaString.substring(textArea.selectionEndIndex,textAreaString.length);
?????startPart+=insertString;
?????startPart+=endPart;
?????textAreaString = startPart;
????}
???}
???
???private function changeInsertHandler():void {
????insertString = insertInput.text;
???}
??]]>
?</mx:Script>
?<mx:TextArea id="textArea" x="10" y="21" width="298" height="158" text="{textAreaString}"/>
?<mx:Button x="316" y="20" label="Insert" click="insertHandler();"/>
?<mx:TextInput id="insertInput" x="316" y="50" text="{insertString}" change="changeInsertHandler();"/>
</mx:Application>

  相关解决方案