a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > Regex > 正文

Html轉換UBB的程序的教程

2024-09-07 17:40:16
字體:
來源:轉載
供稿:網友

在正則表達式中我們經常會需要將Html轉換UBB,但是對于Html轉換UBB的程序是很多小伙伴們都不知道要如何操作,那么下面錯新小編為大家介紹Html轉換UBB的程序的教程。

這個功能主要是讓?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="([^"]+)"[^>]*>/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(/>/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="about:blank"?border="0"?frameborder="0"></iframe>
</td>
</tr>
<tr>
<td?class="tip">
?????????轉換輸出代碼?>></td>
</tr>
<tr>
<td>
?????????<textarea?id="ReCode"?readonly="readonly"></textarea>
????????</td>
</tr>
</table>
</body>
</html>

上文提供的是關于Html轉換UBB的程序的教程,大家不妨可以嘗試一下。只要你去發現,去努力,沒有什么是不可能的。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蜜臀av性久久久久av蜜臀妖精 | 成人精品 | 久久久久女教师免费一区 | 欧美久久久精品 | 91精品福利 | 无套内谢孕妇毛片免费看红桃影视 | 日本一区二区不卡视频 | 欧美一区永久视频免费观看 | 国产精品久久久久久福利 | 久久se精品一区精品二区 | 成视频年人免费看黄网站 | 久久小视频 | 中文字幕不卡在线观看 | 亚洲一区二区精品视频 | 日韩一区欧美一区 | 91精品国产高清自在线观看 | 国产精品原创巨作av色鲁 | a天堂中文在线 | 中文字幕日韩欧美 | 精品福利在线观看 | 极情综合网 | 午夜视| 久99久在线观看 | 蜜桃一本色道久久综合亚洲精品冫 | 成人精品视频在线 | 91精品视频播放 | 成人亚洲一区 | 亚洲午夜精品久久久久久app | 国产精品一线二线在线观看 | 直接在线观看的三级网址 | 91污视频网站 | 亚洲伊人久久综合 | 国产精品久久久久久久一区探花 | 久草精品在线 | 欧美性吧 | 欧美日韩在线免费观看 | 呦呦在线视频 | vagaa欧洲色爽免影院 | 亚洲欧美激情精品一区二区 | 久久久久久久久久久久久久久久久久久久 | 国产乱码精品一区二区三区手机版 |