如果我在spark TextArea中给出restrict =“[a-z] [A-Z]”,并将内容粘贴到其中,则会删除所有换行符。手动按Enter键工作正常。问题在哪里?
<s:TextArea restrict="[A-Z][a-z]"/>
mx TextArea工作正常。
答案 0 :(得分:0)
如果限制它,换行符将无效。试着这样做:
<s:TextArea restrict="A-Za-z\n"/>
答案 1 :(得分:0)
protected function textArea_changingHandler(event:TextOperationEvent):void
{
if (event.operation is PasteOperation)
{
event.preventDefault();
var txt:String = Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT).
toString().replace(/[^A-Za-z0-9\s]/ig, "");
var curPos1:Number = textArea.selectionAnchorPosition;
var curPos2:Number = textArea.selectionActivePosition;
if (curPos2 < curPos1)
{
var t:Number = curPos1;
curPos1 = curPos2;
curPos2 = t;
}
if (textArea.text.length > 0)
{
textArea.text = textArea.text.substr(0, curPos1) + txt + textArea.text.substr(curPos2, textArea.
text.length);
}
else
{
textArea.text = txt;
}
textArea.selectRange(curPos1 + txt.length, curPos1 + txt.length);
event.preventDefault();
}
}
这有效地处理了粘贴期间可能发生的所有场景/操作。