kindeditor在线文本编辑器过滤HTML的方法
发布日期:2021-08-15 09:33:39 浏览次数:14 分类:技术文章

本文共 2122 字,大约阅读时间需要 7 分钟。

在使用kindeditor文本编辑器时遇到的问题,客户直接从Excel里粘贴文本内容到文本编辑器中(能不能再懒一些),然后不调整粘贴内容直接就保存(你敢不敢再懒一些)!对于这种很无语的行径,我只能对他大吼一声,我做一个标签过滤吧,这样你粘贴就不会出现问题了(怂?谁惹得起客户)。

过滤方法也简单:

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']            }           });});

 

转载于:https://www.cnblogs.com/codeit/p/5388084.html

转载地址:https://blog.csdn.net/weixin_30757793/article/details/99549963 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:TC358743XBG:HDMI转MIPI CSI参考设计
下一篇:JMeter学习(九)--FTP测试计划

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年03月29日 03时51分55秒