下面图老师小编要跟大家分享关于HTML及UBB标记的闭合,简单的过程中其实暗藏玄机,还是要细心学习,喜欢还请记得收藏哦!
【 tulaoshi.com - Web开发 】
代码还有待完善:
代码如下:
script type="text/javascript"
// Close HTML Tags --------------------------------------------
function closeHTML(str){
var arrTags=["span","font","b","u","i","h1","h2","h3","h4","h5","h6","p","li","ul","table","div"];
for(var i=0;iarrTags.length;i++){
var intOpen=0;
var intClose=0;
var re=new RegExp(""+arrTags[i]+"( [^\]+|)","ig");
var arrMatch=str.match(re);
if(arrMatch!=null) intOpen=arrMatch.length;
re=new RegExp("\/"+arrTags[i]+"","ig");
arrMatch=str.match(re);
if(arrMatch!=null) intClose=arrMatch.length;
for(var j=0;jintOpen-intClose;j++){
str+="/"+arrTags[i]+"";
}
/*for(var j=(intOpen-intClose-1);j=0;j--){
str+="/"+arrTags[i]+"";
}*/
}
return str;
}
// Close UBB Tags --------------------------------------------
function closeUBB(str){
var arrTags=["code","quote","list","color","align","font","size","b"];
for(var i=0;iarrTags.length;i++){
var intOpen=0;
var intClose=0;
var re=new RegExp("["+arrTags[i]+"(=[^[]]+|)]","ig");
var arrMatch=str.match(re);
if(arrMatch!=null) intOpen=arrMatch.length;
re=new RegExp("[/"+arrTags[i]+"]","ig");
arrMatch=str.match(re);
if(arrMatch!=null) intClose=arrMatch.length;
for(var j=0;jintOpen-intClose;j++){
str+="[/"+arrTags[i]+"]";
}
}
return str;
}
alert(closeHTML("正常:div class='testBox'ullib加粗/bspan字体哈哈"));
alert(closeHTML("有错:div class='testBox'pullib加粗/bspan字体哈哈"));
/script
来源:http://www.tulaoshi.com/n/20160219/1605383.html
看过《关于HTML及UBB标记的闭合》的人还看了以下文章 更多>>