欢迎来到福编程网,本站提供各种互联网专业知识!

关于HTML及UBB标记的闭合

发布时间:2006-12-11 作者: 来源:转载
代码还有待完善:复制代码代码如下://CloseHTMLTags--------------------------------------------functioncloseHTML(str){vararrTags=["span","font","b","u","i","h1","h2","h3","h4","h5","h6","p","li","ul","table","div
代码还有待完善:
复制代码 代码如下:
//CloseHTMLTags--------------------------------------------
functioncloseHTML(str){
vararrTags=["span","font","b","u","i","h1","h2","h3","h4","h5","h6","p","li","ul","table","div"];

for(vari=0;ivarintOpen=0;
varintClose=0;

varre=newRegExp("<"+arrTags[i]+"([^<>]+|)>","ig");
vararrMatch=str.match(re);
if(arrMatch!=null)intOpen=arrMatch.length;

re=newRegExp("","ig");
arrMatch=str.match(re);
if(arrMatch!=null)intClose=arrMatch.length;

for(varj=0;jstr+="";
}
/*for(varj=(intOpen-intClose-1);j>=0;j--){
str+="";
}*/
}

returnstr;
}

//CloseUBBTags--------------------------------------------
functioncloseUBB(str){
vararrTags=["code","quote","list","color","align","font","size","b"];

for(vari=0;ivarintOpen=0;
varintClose=0;

varre=newRegExp("["+arrTags[i]+"(=[^[]]+|)]","ig");
vararrMatch=str.match(re);
if(arrMatch!=null)intOpen=arrMatch.length;

re=newRegExp("[/"+arrTags[i]+"]","ig");
arrMatch=str.match(re);
if(arrMatch!=null)intClose=arrMatch.length;

for(varj=0;jstr+="[/"+arrTags[i]+"]";
}
}

returnstr;
}

alert(closeHTML("正常:

  • 加粗字体哈哈"));
    alert(closeHTML("有错:

    • 加粗字体哈哈"));

相关推荐