Flex 如何获取Textarea的选择文本
1个回答
展开全部
publicvar beginIndex:int; //记录开始选择的索引publicvar endIndex:int; //记录选择结束的索引publicvar chooseStr:String; //记录选择的词语publicvar resultStr:String=""; //记录选择所剩结果 protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void{note.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDownHandler);}/* 当鼠标按下时记录第一个字符索引值 */publicfunction onMouseDownHandler(evt:MouseEvent):void{mouseDown=true;
beginIndex=note.selectionBeginIndex;
this.note.addEventListener(MouseEvent.MOUSE_MOVE,onMoveHandler);}publicfunction onMoveHandler(evt:MouseEvent):void{if(mouseDown){this.note.addEventListener(MouseEvent.MOUSE_UP,onMouseUpHandler);}}/* 记录选择完之后的索引值,并处理选择后的逻辑 */publicfunction onMouseUpHandler(evt:MouseEvent):void{endIndex=note.selectionEndIndex;
chooseStr=note.text.slice( beginIndex,endIndex ) //处理字符串,得到选中的词 trace(chooseStr);}]]></fx:Script>
<mx:TextArea width="800" height="50" id="note" fontSize="14" fontWeight="bold" editable="false" selectable="false" text="注意:选择词语的时候必须从左到右选择,不能双击选择或者从右往左选择"/>
beginIndex=note.selectionBeginIndex;
this.note.addEventListener(MouseEvent.MOUSE_MOVE,onMoveHandler);}publicfunction onMoveHandler(evt:MouseEvent):void{if(mouseDown){this.note.addEventListener(MouseEvent.MOUSE_UP,onMouseUpHandler);}}/* 记录选择完之后的索引值,并处理选择后的逻辑 */publicfunction onMouseUpHandler(evt:MouseEvent):void{endIndex=note.selectionEndIndex;
chooseStr=note.text.slice( beginIndex,endIndex ) //处理字符串,得到选中的词 trace(chooseStr);}]]></fx:Script>
<mx:TextArea width="800" height="50" id="note" fontSize="14" fontWeight="bold" editable="false" selectable="false" text="注意:选择词语的时候必须从左到右选择,不能双击选择或者从右往左选择"/>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询