⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 9-8 ubb代码转换.htm

📁 JAVASCRIPT完全自学手册,中源码的验证修订实例
💻 HTM
字号:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>9-8  UBB代码转换</title>
<!-- 样式表 -->
<style>
* { font-size:12px; font-family:宋体, Arial; } /*规定了所有的字体样式*/
body { background-color:buttonface; border-width:0px; margin:0px; padding:5px; }
textarea { border-width:1px; width:200px; height:100px; margin-bottom:5px; }
input { border-width:1px; margin-bottom:5px; }
</style>
<script>
function ubb2html(){
    var str = $("t1").value;
    //将UBB代码中的大于号、小于号等转换为HTML实体,以保证安全性
    str = str.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/ /g,"&nbsp;").replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\r\n/g,"<br>");
    //将UBB代码转换为对应的HTML代码
    str = str.replace(/\[url\](.+?)\[\/url\]/ig,"<a href=\"$1\">$1<\/a>");
    str = str.replace(/\[url=(.+)\](.+?)\[\/url\]/ig,"<a href=\"$1\">$2<\/a>");
    str = str.replace(/\[email\](.+?)\[\/email\]/ig,"<a href=\"mailto:$1\">$1<\/a>");
    str = str.replace(/\[b\](.+?)\[\/b\]/ig,"<b>$1<\/b>");
    str = str.replace(/\[i\](.+?)\[\/i\]/ig,"<i>$1<\/i>");
    str = str.replace(/\[img\](.+?)\[\/img\]/ig,"<img src=\"$1\" \/>");
    str = str.replace(/\[quote\](.+?)\[\/quote\]/ig,"<div class=\"quote\">$1<\/div>");
    str = str.replace(/\[(u|small|h1|h2|h3|h4|h5|h6|strike|blink|sub|sup|del|pre|big)\](.+?)\[\/\1\]/ig,"<$1>$2<\/$1>");
    str = str.replace(/\[(\#[0-9a-f]{6})\](.+?)\[\/#\]/ig,"<font color=\"$1\">$2<\/a>");
    $("t2").value = str;
}

function $(str){ return(document.getElementById(str)); }
</script>
</head>
<body style="overflow:auto;">
<table width="100%" >
    <tr>
        <td><b>UBB代码:</b></td>
        <td rowspan="2">
            <input type="button" value="转换" onclick="ubb2html();">
        </td>
        <td><b>HTML代码:</b></td>
    </tr>
    <tr>
        <td><textarea id="t1"></textarea></td>
        <td><textarea id="t2"></textarea></td>
    </tr>
</table>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -