<div class="codetitle"> <span><a style="CURSOR: pointer" data="46703" class="copybut" id="copybut46703" onclick="doCopy('code46703')"><u>複製程式碼</u></a></span>程式碼如下:</div> <div class="codebody" id="code46703"> <br><script type="text/javascript"> <BR>//關閉HTML 標籤 ------------------------------------------ -- <BR> function closeHTML(str){ <BR>var arrTags=["span","font","b","u","i","h1","h2","h3", "h4",“ h5”,“h6”,“p”,“li”,“ul”,“表”,“div”]; <BR>for(var i=0;i<arrTags.length;i ){ <BR>var intOpen=0; <BR>var intClose=0; <BR>var re=new RegExp("\<" arrTags[i] "( [^\<\>] |)\>","ig"); <BR>var arrMatch=str.match(re); <BR>if(arrMatch!=null) intOpen=arrMatch.length; <BR>re=new RegExp("\<\/" arrTags[i] "\>","ig"); <BR>arrMatch=str.match(re); <BR>if(arrMatch!=null) intClose=arrMatch.length; <BR>for(var j=0;j<intOpen-intClose;j ){ <BR>str ="</" arrTags[i] ">"; <BR>} <BR>/*for(var j=(intOpen-intClose-1);j>=0;j--){ <BR>str ="</" arrTags[i] ">" ; <BR>}*/ <BR>} <BR>return str; <BR>} <BR></腳本> <BR></script> </div>