JavaScript implementation style sheet (CSS) format collation and compression _javascript skills

Source: Internet
Author: User
Tags button type
<! 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> &LT;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]
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.