栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

TinyMCE粘贴为纯文本

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

TinyMCE粘贴为纯文本

这就是我要做的粘贴纯文本。

1. paste_preprocess设置(在tinymce init中)

paste_preprocess : function(pl, o) {  //example: keep bold,italic,underline and paragraphs  //o.content = strip_tags( o.content,'<b><u><i><p>' );  // remove all tags => plain text  o.content = strip_tags( o.content,'' );},

2.函数strip_tags(在主文档上)

// Strips HTML and PHP tags from a string // returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'// example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');// returns 2: '<p>Kevin van Zonneveld</p>'// example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");// returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'// example 4: strip_tags('1 < 5 5 > 1');// returns 4: '1 < 5 5 > 1'function strip_tags (str, allowed_tags){    var key = '', allowed = false;    var matches = [];    var allowed_array = [];    var allowed_tag = '';    var i = 0;    var k = '';    var html = '';     var replacer = function (search, replace, str) {        return str.split(search).join(replace);    };    // Build allowes tags associative array    if (allowed_tags) {        allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);    }    str += '';    // Match tags    matches = str.match(/(</?[S][^>]*>)/gi);    // Go through all HTML tags    for (key in matches) {        if (isNaN(key)) {     // IE7 Hack continue;        }        // Save HTML tag        html = matches[key].toString();        // Is tag not in allowed list? Remove from str!        allowed = false;        // Go through all allowed tags        for (k in allowed_array) { // Init allowed_tag = allowed_array[k]; i = -1; if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');} if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');} if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;} // Determine if (i == 0) {     allowed = true;     break; }        }        if (!allowed) { str = replacer(html, "", str); // Custom replace. No regexing        }    }    return str;}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/464818.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号