99欧美日本一区二区留学生-丰满顿熟妇好大bbbbbβ -婷婷五月六月激情综合色中文字幕-永久免费AV网站可以直接看的

萬象時代LOGO

新聞資訊

News

Kindeditor過濾樣式、css,不過濾HTML標簽

DATE:2015-04-22 已瀏覽
443


很多朋友在使用Kindeditor編輯器的時候都會遇到這樣一個問題,如:給A標簽加上title屬性過后,瀏覽的時候,卻神奇般地發(fā)現(xiàn)title屬性沒有了。再次切換html源代碼的時候,返現(xiàn)編輯器將title屬性給刪掉了。追究其根本原因主要是kindeditor設(shè)置了標簽和屬性的默認過濾機制。

一、如何控制kindeditor編輯器不過濾任何標簽?
主要設(shè)置是在頁面內(nèi)創(chuàng)建kindeditor編輯器的時候,設(shè)置其filterMode屬性為true/false來決定是否開啟過濾機制。代碼如下所示:

KindEditor.ready(function (K) {
            editor = K.create('textarea[name="content"]', {
                filterMode: false,//是否開啟過濾模式
           });
});
二、如何設(shè)置Kindeditor編輯器只保留某些標簽和屬性? 面對這樣一個問題,我們可以通過設(shè)置其htmlTags屬性來得以實現(xiàn)。htmlTags指定要保留的HTML標記和屬性。Object的key為HTML標簽名,value為HTML屬性數(shù)組,”.”開始的屬性表示style屬性。例子如下所示:

htmlTags,
{
        font : ['color', 'size', 'face', '.background-color'],
        span : [
                '.color', '.background-color', '.font-size', '.font-family', '.background',
                '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
        ],
        div : [
                'align', '.border', '.margin', '.padding', '.text-align', '.color', 'css',
                '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
                '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
        ],
        table: [
                'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor', 'css',
                '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
                '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
                '.width', '.height', '.border-collapse'
        ],
        'td,th': [
                'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor', 'css',
                '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
                '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
        ],
        a : ['href', 'target', 'name'],
        embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
        img : ['src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
        'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
                'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
                '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
        ],
        pre : ['class'],
        hr : ['class', '.page-break-after'],
        'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : []
}

定義每個標簽的保留屬性,記住形如這樣的類型‘.font-size’ 主要是表示其屬于標簽內(nèi)的style屬性內(nèi)的樣式。形如’src’這一類的,就表示標簽的直接屬性,比如我們在內(nèi)容編輯的時候給div或者table添加的css,就可以通過在相應(yīng)的div或者table,td,th后面添加”css”即可保證css不會被過濾掉。 綜上所述,通過以上兩種方式即可實現(xiàn)kindeditor編輯器的標簽和屬性過濾效果。