手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >一个不错的用JavaScript实现的UBB编码函数
一个不错的用JavaScript实现的UBB编码函数
摘要:functionJsUBB(str){varre=//[i/](.[^/[]*)/[//i/]/gi;str=str.replace(re,...

functionJsUBB(str)

{

varre=//[i/](.[^/[]*)/[//i/]/gi;

str=str.replace(re,"<i>$1</i>");//斜体字

re=//[b/](.[^/[]*)/[//b/]/gi;

str=str.replace(re,"<b>$1</b>");//粗体字

re=//[u/](.[^/[]*)/[//u/]/gi;

str=str.replace(re,"<u>$1</u>");//下划线

re=//[color=(.[^/[]*)/](.[^/[]*)/[//color/]/gi;

str=str.replace(re,"<fontcolor=$1>$2</font>");//字体颜色

re=//[size=([1-7])/](.[^/[]*)/[//size/]/gi;

str=str.replace(re,"<fontsize=$1>$2</font>");//字体大小

re=//[face=(.[^/[]*)/](.[^/[]*)/[//face/]/gi;

str=str.replace(re,"<fontface=$1>$2</font>");//字体

re=//[center/](.[^/[]*)/[//center/]/gi;

str=str.replace(re,"<divalign='center'>$1</div>");//居中

re=//[right/](.[^/[]*)/[//right/]/gi;

str=str.replace(re,"<divalign='right'>$1</div>");//右对齐

re=//[quote/](.[^/[]*)/[//quote/]/gi;//引用

str=str.replace(re,"<tablebgcolor='#E6FFE6'width='90%'style='border:1px#009900dotted'align='center'><tr><tdclass='td1'>$1</td></tr></table>");

re=//[fly/](.*)/[//fly/]/gi;//飞行

str=str.replace(re,"<marqueewidth=90%behavior=alternatescrollamount=3>$1</marquee>");

re=//[move/](.*)/[//move/]/gi;//移动

str=str.replace(re,"<MARQUEEscrollamount=3>$1</marquee>");

re=//[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)/](.[^/[]*)/[//SHADOW]/gi;//阴影

str=str.replace(re,"<tablewidth=$1><tr><tdstyle='filter:shadow(color=$2,strength=$3)'>$4</td></tr></table>");

re=//[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)/](.[^/[]*)/[//GLOW]/gi;//外发光

str=str.replace(re,"<tablewidth=$1><tr><tdstyle='filter:glow(color=$2,strength=$3)'>$4</td></tr></table>")

re=//[URL/](.[^/[]*)/[//URL/]/gi;

str=str.replace(re,"<ahref='$1'target=_blank>$1</a>");//超链接1

re=//[URL=(.[^/[]*)/](.[^/[]*)/[//URL/]/gi;

str=str.replace(re,"<ahref='$1'target=_blank>$2</a>");//超链接2

re=//[EMAIL/]([/w-]+(/.[/w-]+)*@[/w-]+(/.[/w-]+)+)/[//EMAIL/]/gi;

str=str.replace(re,"<ahref='mailto:$1'>$1</a>");//电子邮件链接1

re=//[EMAIL=([/w-]+(/.[/w-]+)*@[/w-]+(/.[/w-]+)+)/](.[^/[]*)/[//EMAIL/]/gi;

str=str.replace(re,"<ahref='mailto:$1'>$4</a>");//电子邮件链接2

re=//[img/](.[^/[]*)/[//img/]/gi;

str=str.replace(re,"<ahref='$1'target=_blank><imgsrc='$1'border='0'alt='单击在新窗口浏览'></a>");//图片

re=/:em(/d{1,}):/gi;

str=str.replace(re,"<imgsrc='emot/$1.gif'border='0'>");//表情图标

returnstr;

}

【一个不错的用JavaScript实现的UBB编码函数】相关文章:

javascript实现Table排序的方法

用JavaScript实现页面重定向功能的教程

JavaScript里实用的原生API汇总

JavaScript实现广告的关闭与显示效果实例

一个很简单的办法实现TD的加亮效果.

JavaScript基于setTimeout实现计数的方法

JavaScript实现鼠标滑过处生成气泡的方法

用JavaScript实现对话框的教程

JavaScript实现身份证验证代码

在JavaScript中使用NaN值的方法

精品推荐
分类导航