javascript实现的样式表(CSS) 格式整理与压缩
样式表(CSS) 格式整理与压缩
html,body,form,fieldset,textarea { height:100%; margin:0; padding:0; border:0; font-size:10pt; background:#eee; }
form { margin:0 1%; overflow:hidden; }
legend { line-height:3em; font-weight:bolder; }
button { float:left; margin:1% 1% 0 0; cursor:pointer; }
textarea { width:100%; height:20em; border:1px solid #ccc; display:block; background:#fff; }
样式表(CSS) 格式整理与压缩
body * { font-size:10pt; }/* ss sda */
p
{ clear:left; padding:5px 10px;
}
td
,
fieldset
{ padding : 10px ; }
textarea {
width:90%;
height:10em;
}
压缩代码
格式(多行)
格式(单行)
还原代码
function $(id){return document.getElementById(id);}
function codeZip(obj){
this.S=function(){
var code=obj.value;
if(!this.codeZ||this.codeZ=="")this.codeZ=code;
code=code.replace(/(\n|\t|\s)*/ig,'$1');
code=code.replace(/\n|\t|\s(\{|\}|\,|\:|\;)/ig,'$1');
code=code.replace(/(\{|\}|\,|\:|\;)\s/ig,'$1');
return code;
}
this.A=function(){
var code=this.S();
return code;
}
this.B=function(){
var code=this.S();
code=code.replace(/(\{)/ig,' $1');
code=code.replace(/(\{|\;)/ig,'$1\n\t');
code=code.replace(/\t*(\})/ig,'$1\n');
code=code.replace(/(\*\/)/ig,'$1\n');
return code;
}
this.C=function(){
var code=this.S();
code=code.replace(/(\})/ig,'$1\n');
code=code.replace(/(\*\/)/ig,'$1\n');
return code;
}
this.Z=function(){
return (this.codeZ)?this.codeZ:obj.value;
}
var my=this;
obj.onkeydown=function(){
my.codeZ="";
}
}
var code=new codeZip($('codeText'));
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]