【问题标题】:Highlight part of a text in an extjs textarea突出显示 extjs textarea 中的部分文本
【发布时间】:2013-01-27 17:12:51
【问题描述】:

我需要在文本区域中突出显示部分文本。我已经看到它是用 jquery 完成的,但我不能使用 jquery,因为我正在开发的应用程序已经使用了 extjs(textarea 只是应用程序的一小部分)。这是 jquery 示例的链接:http://www.strangeplanet.fr/work/jquery-highlighttextarea/ 我正在使用 extjs 2.3.0

message 是 Extjs Textarea,我正在尝试突出显示文本。

var message = new Ext.form.TextArea({
        hideLabel: true,
        id: 'smshl',
        name       : 'smshl',
        emptyText: 'enter message here',
        anchor: '90%',
        allowBlank: false,
        style:'overflow:hidden;style:margin:15px;',
        height: 90,
        minLength: 1,
        minLengthText: 'You cannot send a blank text',
        maxLength: userObj.smsLength,
        maxLengthText: 'Sorry, Maximum length of message exceeded',
        preventScrollbars: true,
        enableKeyEvents: true,
        listeners:{
            keyup: function() {
                this.highlightTextarea({
                    words: ["first word","another word"]
                });
            }
        }
    })

【问题讨论】:

  • 我不确定我是否理解是什么阻止了您使用您链接到的 jQuery 插件。在同一个应用程序中同时使用 ExtJS 和 jQuery 是完全可能且容易的。
  • 那是因为我不知道该怎么做。我尝试使用 jquery 插件,但没有成功。我已经编辑了我的问题以包含部分代码。
  • 你需要包含 jQuery 库和你的插件,试试这个教程:docs.jquery.com/Tutorials:Using_Ext_With_jQuery

标签: extjs textarea extjs2


【解决方案1】:

我终于想通了,要使我在问题中发布的代码正常工作,我所要做的就是替换 this.highlightTextarea with jQuery('#'+this.getId()).highlightTextarea

所以代码变成:

var message = new Ext.form.TextArea({
        hideLabel: true,
        id: 'smshl',
        name       : 'smshl',
        emptyText: 'enter message here',
        anchor: '90%',
        allowBlank: false,
        style:'overflow:hidden;style:margin:15px;',
        height: 90,
        minLength: 1,
        minLengthText: 'You cannot send a blank text',
        maxLength: userObj.smsLength,
        maxLengthText: 'Sorry, Maximum length of message exceeded',
        preventScrollbars: true,
        enableKeyEvents: true,
        listeners:{
            keyup: function() {
                jQuery('#'+this.getId()).highlightTextarea.highlightTextarea({
                    words: ["first word","another word"]
                });
            }
        }
    })

【讨论】:

    猜你喜欢
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    相关资源
    最近更新 更多