将 html 转成 ubb代码的小脚本
将 html 转成 ubb代码的小脚本
发布时间:2016-12-29 来源:查字典编辑
摘要://codedbywindy_sk20031218functionhtml_trans(str){str=str.replace(/r/g,...

//coded by windy_sk 20031218 function html_trans(str) { str = str.replace(/r/g,""); str = str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/ig,""); str = str.replace(/]*?>([wW]*?)/ig,""); str = str.replace(/]+href="([^"]+)"[^>]*>(.*?)/ig,"n$1n"); str = str.replace(/]+color=([^ >]+)[^>]*>(.*?)/ig,"n[color=$1]$2[/color]n"); str = str.replace(/]+src="([^"]+)"[^>]*>/ig,"n[img]$1[/img]n"); str = str.replace(//ig,"[$1b]"); str = str.replace(//ig,"[$1b]"); str = str.replace(//ig,"[$1u]"); str = str.replace(//ig,"[$1i]"); str = str.replace(/ /g," "); str = str.replace(/&/g,"&"); str = str.replace(/"/g,"""); str = str.replace(//g,">"); str = str.replace(//ig,"n"); str = str.replace(/]*?>/g,""); str = str.replace(/[url=([^]]+)]n([img]1[/img])n[/url]/g,"$2"); str = str.replace(/n+/g,"n"); return str; }

function trans(){ var str = ""; rtf.focus(); rtf.document.body.innerHTML = ""; rtf.document.execCommand("paste"); str = rtf.document.body.innerHTML; if(str.length == 0) { alert("剪切版不存在超文本数据!"); return ""; } return html_trans(str); }

启用超文本粘贴转换

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新正则表达式学习
热门正则表达式学习
编程开发子分类