当前位置:首页 > 通信资讯 > 正文

只写了几个常用的标签,如果要添加其他标签,按照已有的正则照猫画虎

(存储于剪切板的超文本和源文件有可能是不同的!!也就是说浏览器已经对原有html进行了规范化)

  1. <scriptLanguage="JavaScript1.2">//codedbywindy_sk<windy_sk@126.com>20031218functionhtml_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(/<a[^>]+href="([^"]+)"[^>]*>(.*?)<\/a>/ig,"\n[url=$1]$2[/url]\n");str=str.replace(/<font[^>]+color=([^>]+)[^>]*>(.*?)<\/font>/ig,"\n[color=$1]$2[/color]\n");str=str.replace(/<img[^>]+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(/&nbsp;/g,"");str=str.replace(/&amp;/g,"&");str=str.replace(/&quot;/g,"\"");str=str.replace(/&lt;/g,"<");str=str.replace(/&gt;/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");returnstr;}functiontrans(){varstr="";rtf.focus();rtf.document.body.innerHTML="";rtf.document.execCommand("paste");str=rtf.document.body.innerHTML;if(str.length==0){alert("剪切版不存在超文本数据!");return"";}returnhtml_trans(str);}</script><textareastyle="width:100%;height:200px"id="text"class="textarea"onbeforepaste="if(document.getElementById('x_paste').checked){window.clipboardData.setData('text',trans());this.focus();}"></textarea><iframescrolling="no"id="rtf"src="about:blank"MARGINHEIGHT="0"MARGINWIDTH="0"style="width:0px;height:0px;"></iframe><inputtype="button"value="转换剪切版超文本数据"onclick="document.getElementById('text').value+=trans()"><inputtype="checkbox"id="x_paste"><labelfor="x_paste">启用超文本粘贴转换</label><script>rtf.document.designMode="On";</script>

使用说明

在别的网页中选择HTML内容,比如有链接,或者颜色的拷贝。

点击运行代码按钮

直接点击转换

出来的就是论坛专用的ubb代码了

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。