无为清净楼资源网 Design By www.qnjia.com
这个功能主要是让 UBB 转贴的时候方便点.
1.自动识别图片,超链接,字体颜色,和字体加粗,倾斜,下划线的HTML代码,并且转换为UBB代码.
2.兼容 IE 和 Mozilla多种浏览器
<html>
<head>
<title>Html转换程序</title>
<SCRIPT language="JavaScript1.2">
function HtmlToUBB(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="/UploadFiles/2021-04-02/([^">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(/>/g,">");
str = str.replace(/<br>/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 = "";
str = document.getElementById('edit').contentWindow.document.body.innerHTML;
if (str.length == 0) {
alert("无转换内容!请使用 Ctrl+V 把内容复制到下面的编辑框内");
}
document.getElementById('ReCode').value=HtmlToUBB(str);
}
function clearCode(){
document.getElementById('ReCode').value="";
}
function Start() {
document.getElementById('edit').contentWindow.document.designMode = "on";
try {
document.getElementById('edit').contentWindow.document.execCommand("undo", false, null);
} catch (e) {
alert("你的Mozilla浏览器不支持在线RichEditor");
}
}
function ViewSource(Source){
var Html;
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=""
}
}
</SCRIPT>
<style>
body{background:#688ABD;margin:2px;}
label{color:#fff;}
th{font-size:14px;font-family:verdana,宋体;font-weight:bold;color:fc6;text-align:left}
#sCode{width:400;height:150px;border:1px solid #1F2F47;margin-top:0px !important;margin-top:-1px;margin-bottom:0px !important;margin-bottom:-1px;}
#ReCode{width:400;height:150px;border:1px solid #1F2F47;font-size:12px;}
#edit{width:398;height:148px;border:1px solid #1F2F47;background:#fff;font-size:12px}
.input{
border-top:1px solid #fff;
border-right:1px solid #003;
border-bottom:1px solid #003;
border-left:1px solid #fff;
background:#F4F7FB;
}
.tip{
color:#ffc;
font-weight:bold;
font-size:12px;
font-family:宋体;
}
</style>
</head>
<body onload="Start()" style="">
<table border="0" align="center">
<tr>
<th style="">Html转换UBB程序</th>
</tr>
<tr>
<td style="font-size:12px;">
<label for="Source"><input type="checkbox" id="Source" onclick="ViewSource(this.checked)">查看源代码 </label>
<input id="tranButton" type="button" value="转 换" onclick="trans()" class="input">
<input type="button" value="清 除" onclick="clearCode()" class="input"></td>
</tr>
<tr>
<td class="tip">
<span id="tip">请使用 Ctrl+V 把内容复制到这里 </span></td>
</tr>
<tr>
<td>
<textarea id="sCode" style="display:none"></textarea>
<iframe id="edit"src="/UploadFiles/2021-04-02/about:blank"></td>
</tr>
<tr>
<td class="tip">
转换输出代码 </td>
</tr>
<tr>
<td>
<textarea id="ReCode" readonly="readonly"></textarea>
</td>
</tr>
</table>
</body>
</html>
1.自动识别图片,超链接,字体颜色,和字体加粗,倾斜,下划线的HTML代码,并且转换为UBB代码.
2.兼容 IE 和 Mozilla多种浏览器
<html>
<head>
<title>Html转换程序</title>
<SCRIPT language="JavaScript1.2">
function HtmlToUBB(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="/UploadFiles/2021-04-02/([^">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(/>/g,">");
str = str.replace(/<br>/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 = "";
str = document.getElementById('edit').contentWindow.document.body.innerHTML;
if (str.length == 0) {
alert("无转换内容!请使用 Ctrl+V 把内容复制到下面的编辑框内");
}
document.getElementById('ReCode').value=HtmlToUBB(str);
}
function clearCode(){
document.getElementById('ReCode').value="";
}
function Start() {
document.getElementById('edit').contentWindow.document.designMode = "on";
try {
document.getElementById('edit').contentWindow.document.execCommand("undo", false, null);
} catch (e) {
alert("你的Mozilla浏览器不支持在线RichEditor");
}
}
function ViewSource(Source){
var Html;
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=""
}
}
</SCRIPT>
<style>
body{background:#688ABD;margin:2px;}
label{color:#fff;}
th{font-size:14px;font-family:verdana,宋体;font-weight:bold;color:fc6;text-align:left}
#sCode{width:400;height:150px;border:1px solid #1F2F47;margin-top:0px !important;margin-top:-1px;margin-bottom:0px !important;margin-bottom:-1px;}
#ReCode{width:400;height:150px;border:1px solid #1F2F47;font-size:12px;}
#edit{width:398;height:148px;border:1px solid #1F2F47;background:#fff;font-size:12px}
.input{
border-top:1px solid #fff;
border-right:1px solid #003;
border-bottom:1px solid #003;
border-left:1px solid #fff;
background:#F4F7FB;
}
.tip{
color:#ffc;
font-weight:bold;
font-size:12px;
font-family:宋体;
}
</style>
</head>
<body onload="Start()" style="">
<table border="0" align="center">
<tr>
<th style="">Html转换UBB程序</th>
</tr>
<tr>
<td style="font-size:12px;">
<label for="Source"><input type="checkbox" id="Source" onclick="ViewSource(this.checked)">查看源代码 </label>
<input id="tranButton" type="button" value="转 换" onclick="trans()" class="input">
<input type="button" value="清 除" onclick="clearCode()" class="input"></td>
</tr>
<tr>
<td class="tip">
<span id="tip">请使用 Ctrl+V 把内容复制到这里 </span></td>
</tr>
<tr>
<td>
<textarea id="sCode" style="display:none"></textarea>
<iframe id="edit"src="/UploadFiles/2021-04-02/about:blank"></td>
</tr>
<tr>
<td class="tip">
转换输出代码 </td>
</tr>
<tr>
<td>
<textarea id="ReCode" readonly="readonly"></textarea>
</td>
</tr>
</table>
</body>
</html>
标签:
简单的Html转换UBB的程序
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年11月15日
2024年11月15日
- 第五街的士高《印度激情版》3CD [WAV+CUE][2.4G]
- 三国志8重制版哪个武将智力高 三国志8重制版智力武将排行一览
- 三国志8重制版哪个武将好 三国志8重制版武将排行一览
- 三国志8重制版武将图像怎么保存 三国志8重制版武将图像设置方法
- 何方.1990-我不是那种人【林杰唱片】【WAV+CUE】
- 张惠妹.1999-妹力新世纪2CD【丰华】【WAV+CUE】
- 邓丽欣.2006-FANTASY【金牌大风】【WAV+CUE】
- 饭制《黑神话》蜘蛛四妹手办
- 《燕云十六声》回应跑路:年内公测版本完成95%
- 网友发现国内版《双城之战》第二季有删减:亲亲环节没了!
- 邓丽君2024-《漫步人生路》头版限量编号MQA-UHQCD[WAV+CUE]
- SergeProkofievplaysProkofiev[Dutton][FLAC+CUE]
- 永恒英文金曲精选4《TheBestOfEverlastingFavouritesVol.4》[WAV+CUE]
- 群星《国风超有戏 第9期》[320K/MP3][13.63MB]
- 群星《国风超有戏 第9期》[FLAC/分轨][72.56MB]