在ExtJs中,如何在TextArea的插入符号位置插入固定的字符串? [英] In ExtJs, how to insert a fixed string at caret position in a TextArea?

查看:77
本文介绍了在ExtJs中,如何在TextArea的插入符号位置插入固定的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题可能是在其他框架中提出的,不确定在我刚接触过的ExtJ上是否存在一个问题.我想知道是否有一个带有TextArea和按钮的简单示例.当按下按钮时,固定字符串"???"插入到TextArea中的光标处.

This question probably is asked in other framework, not sure if there is one on ExtJs, which I am new to. I wonder whether there is a simple example with a TextArea and a button. When the button is pressed, a fixed string "???" is inserted at the cursor in the TextArea.

谢谢.

推荐答案

实际上,您可以直接从DOM进行此操作,方法是使用textareas selectionStart属性找到插入符的位置.

You can actually do this straight from the DOM, using textareas selectionStart attribute to find the caret position.

所以您可以按照以下方式做一些事情

So you could do something along the lines of

textArea.value = textArea.value.substring(0, selectionStart)+'???'+textArea.value.substring(selectionStart);

这是一个 jsfiddle ,它结合使用Ext.get和Ext.getDom进行选择并修改元素.

Here is a jsfiddle demonstrating this using a combination of Ext.get and Ext.getDom to select and modify the elements.

这篇关于在ExtJs中,如何在TextArea的插入符号位置插入固定的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆