百度编辑器添加监控内容改变事件,不要放在editor.read()里面

来源:互联网 发布:淘宝二手回收靠谱吗 编辑:程序博客网 时间:2024/06/03 19:12

百度编辑器添加监控内容改变事件,不要放在editor.read(function(){   })里面,否则显示内容时,没有上面的工具栏,要在编辑器里按个空格符什么的才出来

function add_change_listener(shellId){    //编辑内容改变监听事件    //var shellId = 'container';    //        editor.addListener("contentChange",function(){    //            console.log('内容改变:'+editor.getContent());    //        });    //一般的字符都可以监听,但是@#¥%……这些字符的输入是监听不到的。所以采用如下的方法:    //参考帖子:http://www.cnblogs.com/longze/archive/2013/07/17/3195564.html    $('#' + shellId + ' #edui1_toolbarbox').css('display','none');    editor.fireEvent("contentChange");    var $textarea = $('#' + shellId + '').parent().find('iframe').contents();    var fn = function(){        g_content_changed = true;        console.log('content_changed1, g_content_changed='+g_content_changed);    }    if (document.all) {        $textarea.get(0).attachEvent('onpropertychange',function(e) {            fn();        });    }else{        $textarea.on('input',fn);        $textarea.on('keyup',fn);    }}


0 0