複製代碼 代碼如下:var lCSSCoder={
format : function(s){//格式化代碼
s=s.replace(/\s*([\{\}\:\;\,])\s*/g,"$1");
s=s.replace(/\,[\s\.\#\d]*{/g,"{");
s=s.replace(/([^\s])\{([^\s])/g,"$1 {\n\t$2");
s=s.replace(/([^\s])\}([^\n]*)/g,"$1\n}\n$2");
s=s.replace(/([^\s]);([^\s\}])/g,"$1;\n\t$2");
s=s.replace(/;\s*;/g,";");//清除連續分號
return s;
},
pack :function(s){//壓縮代碼
s=s.replace(/\/\*(.|\n)*?\*\//g,"");//刪除注釋
s=s.replace(/\s*([\{\}\:\;\,])\s*/g,"$1");
s=s.replace(/\,[\s\.\#\d]*\{/g,"{");//容錯處理
s=s.replace(/;\s*;/g,";");//清除連續分號
return s;
}
};
示範代碼: xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
原始代碼: /*PageHead*/<br />#PageHead {float:left;padding:3px 0;border-bottom:1px solid #b0bec7;margin-bottom:6px;}<br />#hCity li {float:left;padding:0 10px 0 0;}<br />#hCity li.fst {padding:0;}<br />#hRight {<br />float:right;padding:0 5px 0 20px;<br />background:url(img/ico_home.gif) no-repeat 0 50%;}<br />.SubPage #hRight { background-image:url(img/ico_favorite.gif);} </p><p>/*PageBody*/<br />#PageBody {float:left;padding:4px 0 0 0;}<br />.SCol {float:left;width:174px;}<br />.MCol {float:right;width:678px;overflow:hidden; } </p><p>#Logo {height:66px;margin:0;padding:0;}<br />/*MailLogin*/<br />#MailLogin {height:32px;}<br />#MailLogin li {float:left;}<br />#MailLogin li.txt {line-height:20px;}<br />#MailLogin li.inp {padding:0 2px;}<br />#MailLogin li.inp input {<br />margin:0;padding:0 4px;border:1px solid #7a9dbb;font:bold 12px/18px tahoma,Geneva,Arial,sans-serif;height:18px; }<br />#MailLogin li.inp input.notClicked {color:#ccc;font-weight:normal;}<br />#MailLogin li.sel {padding:1px 10px 0 0;}<br />#MailLogin li.btn {padding:1px 12px 0 5px;}<br /> |
轉換後:
|