0000000 Javascript(js)UBB代码 - 老吧网

Javascript(js)UBB代码

分类:网站技术 | lao8发表于 2010-1-22 3:46:00

记录下js处理ubb代码的方法:

  1. String.prototype.UBB=function()
    {
    var str=this;
    str=str.replace(/\[br\]/ig,"<br/>");/*回车*/
    str=str.replace(/\[u\](.+?)\[\/u\]/ig,"<u>$1</u>");/*下划线*/
    str=str.replace(/\[i\](.+?)\[\/i\]/ig,"<i>$1</i>");/*斜体*/
    str=str.replace(/\[b\](.+?)\[\/b\]/ig,"<b>$1</b>");/*粗体*/
    str=str.replace(/\[QUOTE\](.+?)\[\/QUOTE\]/ig,"<BLOCKQUOTE><font size=2 face=\"Verdana, Arial\">引用:</font><HR>$1<HR></BLOCKQUOTE>");/*引用*/
    str=str.replace(/\[red\](.+?)\[\/red\]/ig,"<FONT COLOR=\"#ff0000\">$1</FONT>");/*红色字*/
    str=str.replace(/\[gray\](.+?)\[\/gray\]/ig,"<FONT COLOR=\"#77ACAC\">$1</FONT>");/*灰色字*/
    str=str.replace(/\[green\](.+?)\[\/green\]/ig,"<FONT COLOR=\"#77ACAC\">$1</FONT>");/*绿色字*/
    str=str.replace(/\[blue\](.+?)\[\/blue\]/ig,"<FONT COLOR=\"#0055ff\">$1</FONT>");/*蓝色字*/
    str=str.replace(/\[color\=(.+?)\](.+?)\[\/color\]/ig,"<FONT COLOR=\"$1\">$2</FONT>");/*任何颜色*/
    str=str.replace(/\[EMAIL\](\S+\@\S+?)\[\/EMAIL\]/ig,"<A HREF=\"mailto:$1\">$1</A>");/*邮件*/
    str=str.replace(/\[URL\](http:\/\/\S+?)\[\/URL\]/ig,"<A HREF=\"$1\" TARGET=_blank>$1</A>");/*链接http://*/
    str=str.replace(/\[URL\](\S+?)\[\/URL\]/ig,"<A HREF=\"http://$1\" TARGET=_blank>$1</A>");/*链接*/
    str=str.replace(/\[marquee\](.+?)\[\/marquee\]/ig,"<marquee scrollamount=\"3\" onmouseover=\"javascript:this.stop()\" onmouseout=\"javascript:this.start()\">$1</marquee>");/*滚动*/
    str=str.replace(/\[IMGurl\=(http:\/\/\S+?)\](http:\/\/\S+?)\[\/IMGurl\]/ig,"<a href=\"$1\" target=_blank><IMG SRC=\"$2\" border=0 onload=\"javascript:if(this.width>screen.width-366)this.width=screen.width-366\"/></a>");/*带图片链接http://*/
    str=str.replace(/\[IMGurl\=(\S+?)\](\S+?)\[\/IMGurl\]/ig,"<a href=\"http://$1\" target=_blank><IMG SRC=\"http://$2\" border=0 onload=\"javascript:if(this.width>screen.width-366)this.width=screen.width-366\"/></a>");/*带图片链接*/
    str=str.replace(/\[IMG\](\S+?)\[\/IMG\]/ig,"<IMG SRC=\"$1\"/>");/*图片*/
    return str;
    }

使用时就直接

  1. str = str.UBB();
标签:js UBB
收藏到收藏夹

相关"js UBB"文章

网友点评
赵恩之 2010-2-1 12:01:00 | [回复] 
str=str.replace(/\[marquee\](. ?)\[\/marquee\]/ig,"<marquee scrollamount=\"3\" onmouseover=\"javascript:this.stop()\" onmouseout=\"javascript:this.start()\">$1</marquee>");/*滚动*/ str=str.replace(/\[IMGurl\=(http:\/\/\S ?)\](http:\/\/\S ?)\[\/IMGurl\]/ig,"<a href=\"$1\" target=_blank><IMG SRC=\"$2\" border=0 onload=\"javascript:if(this.width>screen.width-366)this.width=screen.width-366\"/></a>");/*带图片链接http://*/ str=str.replace(/\[IMGurl\=(\S ?)\](\S ?)\[\/IMGurl\]/ig,"<a href=\"http://$1\" target=_blank><IMG SRC=\"http://$2\" border=0 onload=\"javascript:if(this.width>screen.width-366)this.width=screen.width-366\"/></a>");/*带图片链接*/ str=str.replace(/\[IMG\](\S ?)\[\/IMG\]/ig,"<IMG SRC=\"$1\"/>");/*图片*/ return str; 有点看不明白 
魔法辞典 2010-2-1 14:07:00 | [回复] 
这个我估计用不上呢!
高于怡 2010-2-1 14:36:00 | [回复] 
天啊。谁来帮帮我,看不懂。5555,学了这么久了
MJ 2010-2-2 23:24:00 | [回复] 
还不错,可以改进的更好!
魔女大神 2010-2-6 15:14:00 | [回复] 
看不懂 不过博主辛苦了 
阿里三八 2010-2-7 21:09:00 | [回复] 
我来回访 呵呵 博主辛苦了
嘟嘟鱼 2010-2-8 11:36:00 | [回复] 
帮我改下博客友情链接地址  快享  www.quickshare.com.cn修改为 www.kuaixiang.net 多谢

发表见解

username(必填)
email(必填)
website

站内搜索

 

按分类归档

lao8 最新文章: