1.自动识别图片,超链接,字体颜色,和字体加粗,倾斜,下划线的HTML代码,并且转换为UBB代码.
2.兼容IE和Mozilla多种浏览器
functionHtmlToUBB(str){
str=str.replace(/r/g,"");
str=str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/ig,"");
str=str.replace(//ig,"");
str=str.replace(/]+href="([^"]+)"[^>]*>(.*?)/ig,"n[url=$1]$2[/url]n");
str=str.replace(/]+color=([^>]+)[^>]*>(.*?)/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(/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");
returnstr;
}
functiontrans(){
varstr="";
str=document.getElementById('edit').contentWindow.document.body.innerHTML;
if(str.length==0){
alert("无转换内容!请使用Ctrl+V把内容复制到下面的编辑框内");
}
document.getElementById('ReCode').value=HtmlToUBB(str);
}
functionclearCode(){
document.getElementById('ReCode').value="";
}
functionStart(){
document.getElementById('edit').contentWindow.document.designMode="on";
try{
document.getElementById('edit').contentWindow.document.execCommand("undo",false,null);
}catch(e){
alert("你的Mozilla浏览器不支持在线RichEditor");
}
}
functionViewSource(Source){
varHtml;
if(Source){
document.getElementById('sCode').value=document.getElementById('edit').contentWindow.document.body.innerHTML;
document.getElementById('edit').style.display="none";
document.getElementById('sCode').style.display="";
document.getElementById('tip').innerText="修改粘贴后的网页源代码>>";
document.getElementById('tranButton').disabled="disabled"
}
else{
document.getElementById('edit').contentWindow.document.body.innerHTML=document.getElementById('sCode').value;
document.getElementById('edit').style.display="";
document.getElementById('sCode').style.display="none";
document.getElementById('edit').contentWindow.document.designMode="on";
document.getElementById('tip').innerText="请使用Ctrl+V把内容复制到这里>>";
document.getElementById('tranButton').disabled=""
}
}
转换输出代码>>