【问题标题】:jQuery Text Editor (jqte), using change eventjQuery 文本编辑器 (jqte),使用更改事件
【发布时间】:2015-05-29 19:59:00
【问题描述】:

我正在尝试使用 jQuery 文本编辑器 (jqte)change() 事件编写一些代码,我有两个函数可以为 textarea 提供 jqte 功能

一个用于加载了 JavaScript 的编辑器,当单击页面中的某些元素时:

function onLoadEditor(){
    jQuery(".comment-editor").jqte({
        // some jqte params, such as fsize: false,indent: false...
        change: function(){ observeEditor(); }
    });
}

以及其他通用功能,适用于具有单个编辑器的页面

jQuery(function() {
    jQuery(".comment-editor").jqte({
        // some jqte params, such as fsize: false,indent: false...
        change: function(){ observeEditor(); }
    });
});

我想访问已触发 change() 事件的具体文本区域的 id(页面中的所有文本区域都有一个 id)

我应该如何编写observeEditor() 函数来实现这一点?或者...我应该如何在 jqte 更改属性中定义函数?

【问题讨论】:

    标签: javascript jquery jquery-events jqte


    【解决方案1】:

    读完这个jQuery blur event with ID and value我已经解决了,下面的代码(简化)

    function onLoadEditor(){
        jQuery(".comment-editor").each(function(idx, elem) {
            jQuery(this).jqte({
                // some jqte params, such as fsize: false,indent: false...
                change: observeEditor(elem.id),
        });
    }
    
    jQuery(function() {
        onLoadEditor();
    });
    

    但现在我有另一个问题......

    正如您在原始问题中看到的那样,单击页面中的某些元素时会调用 onLoadEditor()。然后调用另一个javascript函数jsComment(),构建一个表单(包含textarea.comment-editor字段)并以这种方式呈现

    function jsComment(){
        ...
        var form = '<div class="comments_wrapper ... ';
        jQuery(form).insertAfter(some_element).fadeIn('fast');
        onLoadEditor();
    }
    

    问题是change() 事件仅被触发一次,当表单淡入时,而想法相反,事件应该在用户添加一些文本时触发,而不是在出现时触发......有什么提示吗?

    更新 看完Event binding on dynamically created elements?我已经这样解决了

    function onLoadEditor(){
        jQuery('.comment-editor').each(function(idx, elem) {
            jQuery(this).jqte({
                // some jqte params, such as fsize: false,indent: false...
            });
            jQuery(document).on('change', 
                jQuery('.comment-editor'), 
                function(){ 
                    observeEditor(elem.id); 
                }
            );
        });
    }
    
    jQuery(function() {
        onLoadEditor();
    });
    

    虽然最后我没有使用change() 事件,因为它一直被触发。例如,使用keyup()paste() 表现更好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      • 2019-10-25
      • 1970-01-01
      相关资源
      最近更新 更多