Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Button Ext JS Html编辑器获取所选文本_Button_Extjs_Toolbar_Html Editor - Fatal编程技术网

Button Ext JS Html编辑器获取所选文本

Button Ext JS Html编辑器获取所选文本,button,extjs,toolbar,html-editor,Button,Extjs,Toolbar,Html Editor,我正试图在HtmlEditor的工具栏中插入一个按钮。按钮应通过鼠标或键盘获取所选文本,并在所选文本的开头添加“#”字符,以将其定位为url 据我所知,最好的解决方案是创建一个插件,将按钮添加到html编辑器工具栏中。我找到了创建代码,但问题是如何获取所选文本?Ext js 2.2版 下面是为html编辑器工具栏按钮创建插件的代码: Ext.ns('Ext.ux.form.HtmlEditor'); Ext.ux.form.HtmlEditor.NewLine = Ext.extend

我正试图在HtmlEditor的工具栏中插入一个按钮。按钮应通过鼠标或键盘获取所选文本,并在所选文本的开头添加“#”字符,以将其定位为url

据我所知,最好的解决方案是创建一个插件,将按钮添加到html编辑器工具栏中。我找到了创建代码,但问题是如何获取所选文本?Ext js 2.2版

下面是为html编辑器工具栏按钮创建插件的代码:

Ext.ns('Ext.ux.form.HtmlEditor');

    Ext.ux.form.HtmlEditor.NewLine = Ext.extend(Ext.util.Observable, {
        init:function (cmp) {
            this.cmp = cmp;
            this.cmp.on('render', this.onRender, this);
        },
        onRender:function () {
            this.cmp.getToolbar().addButton([
                {
                    iconCls:'newline', //your iconCls here
                    handler:function () {
                        this.cmp.insertAtCursor('<br>&nbsp;');

                    },
                    scope:this
                }
            ]);
        }
    });
Ext.ns('Ext.ux.form.HtmlEditor');
Ext.ux.form.HtmlEditor.NewLine=Ext.extend(Ext.util.Observable{
初始化:函数(cmp){
this.cmp=cmp;
this.cmp.on('render',this.onRender,this);
},
onRender:function(){
这个.cmp.getToolbar().addButton([
{
iconCls:'newline',//您的iconCls在这里
处理程序:函数(){
this.cmp.insertAtCursor(“
”); }, 范围:本 } ]); } });
您可以像这样获取所选文本:
window.getSelection()

这将为您提供一个选择对象。如果只想获取文本:
window.getSelection().toString()

但是,如果您想将内容设置为粗体或其他形式,则需要检查所选内容是否在编辑器中。所需的一切都在选择对象内部

=>更正:htmlEditor使用iframe,您可以通过函数获取iframe窗口

请注意,这仅适用于现代浏览器(而不是

也许能帮上忙。。。你能把extjs版本添加到问题中吗?window.getSelection().toString()在那里工作!!非常感谢!我的示例的确切行是:var text=this.cmp.getWin().getSelection().toString();是的,只是:)getWin会有用的。不知道getEditorBody是否使用getSelection方法返回对象。getDoc可能也可以工作。getEditor主体返回对象,getDoc也可以工作。哇,我很感激你的回答!在这样的环境中是很好的!如果我投你的票会更好,但不幸的是我一点名声都没有:Dlol!没问题,不过你可以这样回答:)