<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > < HTML xmlns= "http://www.w3.org/1999/xhtml" > <pead> <meta http-equiv= "Content-type" content=; charset=gb2312 "/> <title> style sheet (CSS) format collation and compression </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> </pead> <body> <form action= "" onsubmit= "return false" ><fieldset> <LEGEND&G t; style sheet (CSS) format collation and compression </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= "$ (' Codetext '). Value=code. A (); " > Zip code </button> <button type= "button" onclick= "$ (' Codetext '). Value=code. B (); " > Format (Multiline) </button> <button type= "button" onclick= "$ (' Codetext '). Value=code. C (); " > Format (single line) </button> <button type= "button" onclick= "$ (' Codetext '). Value=code. Z (); " > Restore Code </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, ' $ '); Code=code.replace (/\n|\t|\s (\{|\}|\,|\:|\;)/ig, ' $ '); Code=code.replace (/(\{|\}|\,|\:|\;) \s/ig, ' $ '); return code; } this. A=function () {var code=this. S (); return code; } this. B=function () {var code=this. S (); Code=code.replace (/(\{)/ig, ' $ '); 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> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]