将 html 转成 ubb代码的小脚本 时间:2021-03-16 人气:0 想了解将 html 转成 ubb代码的小脚本的相关内容吗,在本文为您仔细讲解的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:将,html,转成,ubb代码的小脚本,下面大家一起来学习吧。 <script Language="JavaScript1.2"> //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(/<script[^>]*?>([\w\W]*?)<\/script>/ig,""); str = str.replace(/]+href="([^"]+)"[^>]*>(.*?)<\/a>/ig,"\n$1\n"); str = str.replace(/]+color=([^ >]+)[^>]*>(.*?)<\/font>/ig,"\n[color=$1]$2[/color]\n"); str = str.replace(/]+src="([^"]+)"[^>]*>/ig,"\n[img]$1[/img]\n"); str = str.replace(/<([\/]?)b>/ig,"[$1b]"); str = str.replace(/<([\/]?)strong>/ig,"[$1b]"); str = str.replace(/<([\/]?)u>/ig,"[$1u]"); str = str.replace(/<([\/]?)i>/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); } </script> </textarea> 启用超文本粘贴转换 <script> rtf.document.designMode="On"; </script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容