在kindeditor的使用中,很多朋友可能都發現部分html標簽及部分標簽的部分屬性無效,如a標簽,在新增內容的時候添加一個rel=nofollow屬性,發布之后發現這個屬性沒有了……或者你用highlight實現語法高亮,插入了一個code標簽,發布之后發現這個標簽沒有了……如此怪事,只因kindeditor的htmlTags過濾所致。
當filtMode為true時,編輯器會根據htmlTags設定自動過濾HTML代碼。官方這樣做,主要是為了生成干凈的代碼,但在實際運用中,我們可能需要保留特定的html代碼。如果想保留所有HTML,可以將filterMode設置成false。如果只是想保留特定的部分HTML,需要額外配置htmlTags屬性。
從3.4版本開始默認關閉過濾模式,所以要過濾HTML,需要將filterMode設置成true。
KE.show({ id : 'textarea_id', filterMode : true // true:開啟過濾模式, false:關閉過濾模式 });
我想去掉a標簽 所以直接在kindeditor-min.js 中 搜索htmlTags 把默認的標簽全部刪除,哈哈 成功了。
官方的默認的htmlTags
指定要保留的HTML標記和屬性。哈希數組的key為HTML標簽名,value為HTML屬性數組,"."開始的屬性表示style屬性。
數據類型:Object
{ font : ['color', 'size', 'face', '.background-color'], span : ['style'], div : ['class', 'align', 'style'], table: ['class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'style'], 'td,th': ['class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor', 'style'], a : ['class', 'href', 'target', 'name', 'style'], embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', 'style', 'align', 'allowscriptaccess', '/'], img : ['src', 'width', 'height', 'border', 'alt', 'title', 'align', 'style', '/'], hr : ['class', '/'], br : ['/'], 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : ['align', 'style'], 'tbody,tr,strong,b,sub,sup,em,i,u,strike' : [] }
© 致遠 2020-01-18,原創內容,轉載請注明出錯:kindeditor html代碼過濾