Ext JS 4 TextArea - 如何设置插入点?

发布于 2024-12-19 10:03:31 字数 315 浏览 1 评论 0原文

是否可能/如何设置 ExtJS 4 Textarea 的插入点?

我想插入一些文本(我正在工作),然后我想将插入点设置为从字段开头开始的特定长度:

我正在获取当前内容,在前面插入一些文本。现在我想将插入点移到“-”之后:

//field = my ExtJS text area
var ins = "some text I inserted - \r";
var value =  ins + field.getValue();                            
field.setValue(value);

Is it possible / how do you set the insertion point for an ExtJS 4 Textarea?

I want to insert some text (which I have working), then I want to set the insertion point at a specific length from the beginning of the field:

I am getting the current contents, inserting some text in front. Now I want to move the insertion point to right after the "-":

//field = my ExtJS text area
var ins = "some text I inserted - \r";
var value =  ins + field.getValue();                            
field.setValue(value);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扎心 2024-12-26 10:03:31

没有现成的方法可以实现这一点。

Javascript 安全性不允许您触发按键事件,因此您无法聚焦文本区域,然后触发“CTRL+END”组合键,甚至“END”键。

我在

所以我的答案是,在正式支持之前,您不应该尝试此操作,因为即使您进行了破解,它也可能只能在某些浏览器中正常运行。

There's no out-of-the-box method that allows this.

Javascript security doesn't allow you to fire a keypress event, so you can't focus the textarea and then fire the "CTRL+END" key combo, or even the "END" key, for example.

I played around with the focus() and select() methods on the <textarea> element, with no success being able to get the cursor to appear at the end.

So my answer is that you shouldn't attempt this until it's officially supported, because even if you get a hack to work, it might only function properly in some browsers.

嘿咻 2024-12-26 10:03:31

qaScriptForm 是普通表单

Script 是普通 TextArea

var insertIndex = qaScriptForm.Script.selectionStart;
var value = qaScriptForm.Script.value;
value=value.substr(0,insertIndex)+ " DATEADD(DAY,-7,GETDATE()) "+value.substr(insertIndex);
qaScriptForm.Script.value=value;

qaScriptForm is a normal form

Script is a normal TextArea

var insertIndex = qaScriptForm.Script.selectionStart;
var value = qaScriptForm.Script.value;
value=value.substr(0,insertIndex)+ " DATEADD(DAY,-7,GETDATE()) "+value.substr(insertIndex);
qaScriptForm.Script.value=value;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文