kindeditor在線文本編輯器過濾HTML的方法

在使用kindeditor文本編輯器時遇到的問題,客戶直接從Excel裏粘貼文本內容到文本編輯器中(能不能再懶一些),而後不調整粘貼內容直接就保存(你敢不敢再懶一些)!對於這種很無語的行徑,我只能對他大吼一聲,我作一個標籤過濾吧,這樣你粘貼就不會出現問題了(慫?誰惹得起客戶)。html

過濾方法也簡單:數組

KindEditor.ready(function (K) {
            editor = K.create('textarea[name="content"]', {
                filterMode: true,//是否開啓過濾模式
           });
});

默認filterMode是關閉狀態,首先把filterMode設置爲true,而後增長htmlTags,指定要保留的HTML標記和屬性。哈希數組的key爲HTML標籤名,value爲HTML屬性數組,"."開始的屬性表示style屬性。數據類型:Object編輯器

KindEditor.ready(function (K) {
            editor = K.create('textarea[name="content"]', {
                filterMode: true,//是否開啓過濾模式
                htmlTags : {
                    font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
                    div : [
                        'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
                        '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
                        '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
                    ],
                    a : ['id', 'class', 'href', 'target', 'name'],
                    embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
                    img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
                    'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
                        'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
                        '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
                    ],
                    pre : ['id', 'class'],
                    hr : ['id', 'class', '.page-break-after'],
                    'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
                    iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
            }
           });
});
相關文章
相關標籤/搜索