<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSS代码格式化和加密化</title>
</head>
<body sytle="marign:0px auto;">
<script language="JavaScript">
<!--
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == "string")
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
//CSS代码格式化和加密化
function CSSencode(code)
{
code = code.replace(/\n/ig,"");
code = code.replace(/(\s){2,}/ig,"$1");
code = code.replace(/\t/ig,"");
code = code.replace(/\n\}/ig,"\}");
code = code.replace(/\n\{\s*/ig,"\{");
code = code.replace(/(\S)\s*\}/ig,"$1\}");
code = code.replace(/(\S)\s*\{/ig,"$1\{");
code = code.replace(/\{\s*(\S)/ig,"\{$1");
return code;
}
function CSSdecode(code)
{
code = code.replace(/(\s){2,}/ig,"$1");
code = code.replace(/(\S)\s*\{/ig,"$1\n{");
code = code.replace(/\*\/(.[^\}\{]*)}/ig,"\*\/\n$1}");
code = code.replace(/\/\*/ig,"\n\/\*");
code = code.replace(/;\s*(\S)/ig,";\n\t$1");
code = code.replace(/\}\s*(\S)/ig,"\}\n$1");
code = code.replace(/\n\s*\}/ig,"\n\}");
code = code.replace(/\{\s*(\S)/ig,"\{\n\t$1");
code = code.replace(/(\S)\s*\*\//ig,"$1\*\/");
code = code.replace(/\*\/\s*([^\}\{]\S)/ig,"\*\/\n\t$1");
code = code.replace(/(\S)\}/ig,"$1\n\}");
code = code.replace(/(\n){2,}/ig,"\n");
return code;
}
//-->
</script>
<h3>CSS代码格式化和加密化</h3>
<hr style="width:600px;text-align:left;" />
<textarea name="" rows="" cols="" style="width:600px;height:300px;" id="code">
/*请将CSS代码复制到这里*/
input,button {
height:20px;
background-color: #ffffff;
/*border:1px solid #333333;*/ }
</textarea>
<br>
<input type="submit" onclick="$('code').value = CSSdecode($('code').value);" value="格式化">
<input type="submit" onclick="$('code').value = CSSencode($('code').value);" value="加密化" />
<br>
</body>
</html>


js闭包
JavaScript中的