CSS代碼格式化工具

來源:互聯網
上載者:User

標籤:css代碼格式化

CSS代碼格式化工具


  1. css代碼格式化工具可以:壓縮代碼,格式(多行),格式(單行),還原代碼。

  2. 便於最佳化,節省空間的


以下為源碼:

-------------------------------------

<!DOCTYPE html >

<html>

<head>

<meta charset="UTF-8">


<title>css格式化工具</title>

<style type="text/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; }

</style>

</head><body>

<form action="" onsubmit="return false">

<fieldset>

<legend>css格式化工具</legend>

<textarea name="" rows="" cols="" id="codeText">body * { font-size:10pt; }/* ss sda   */

p 

{ clear:left; padding:5px 10px;

}

td

,

fieldset

{padding: 10px; }

textarea {

width:90%;

height:10em;

}

</textarea>

<button type="button" onclick="$(&#39;codeText&#39;).value=code.A();">壓縮代碼</button>

<button type="button" onclick="$(&#39;codeText&#39;).value=code.B();">格式(多行)</button>

<button type="button" onclick="$(&#39;codeText&#39;).value=code.C();">格式(單行)</button>

<button type="button" onclick="$(&#39;codeText&#39;).value=code.Z();">還原代碼</button>

</fieldset>

</form>

<script type="text/javascript">

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‘));

</script>

</body>

</html>


650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/73/98/wKioL1YCEyWz05LPAAJJ_Rdv2Bc473.jpg" title="dzq-blog.png" alt="wKioL1YCEyWz05LPAAJJ_Rdv2Bc473.jpg" />




本文出自 “wennuanyiran” 部落格,轉載請與作者聯絡!

CSS代碼格式化工具

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.