csdn的前端代码好像不太规范
<script type="text/javascript">
function getCookie( name ) {
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if( arr != null )
{
return decodeURIComponent( arr[ 2 ] );
}
return null;
}
function csdnShowSpaceNotify( data ) {
document.getElementById("header_notice_num").innerHTML = parseInt( data.n ) > 0 ? data.n : 0;
if( parseInt( data.l ) > 0 )
{
document.getElementById("header_letter_num").innerHTML = "("+data.l+")";
}
}
window.csdnShowSpaceNotify = csdnShowSpaceNotify;
var userName = getCookie( "UserNick" );
if ( userName && userName != "Guest" )
{
document.getElementById("login").innerHTML = "";
document.getElementById("showinfo").innerHTML = "<em>"+ userName + "</em><a href=\"http://notify.csdn.net/dashboard\" class=\"notice_num\" id=\"header_notice_num\"></a>我的:<a href=\"http://my.csdn.net/my/letter\">收件箱<span id=\"header_letter_num\"></span></a><a href='http://download.csdn.net/my' class='red'>资源</a> <a href='http://write.blog.csdn.net/' class='red'>博客</a> <a href='http://my.csdn.net/'>空间</a> <a href='https://passport.csdn.net/account/profile'>设置</a>| <a href='https://passport.csdn.net/help/faq'>帮助</a>| <a href='http://passport.csdn.net/account/logout'>退出</a><input type='text' name='passwordtwo' class='search' value='搜索' onfocus=\"if(this.value=='搜索') this.value='';this.style.color='#333'; return true;\" onblur=\"if(this.value=='') this.value='搜索'; this.style.color='#999'; return true;\" id='srch1' />";
}
if ( userName && userName != "Guest" )
{
( function() {
var ca = document.createElement( 'script' );
ca.type = 'text/javascript';
ca.async = true;
ca.src = 'http://my.csdn.net/index.php/service/notifications/getnl?jsonpcallback=csdnShowSpaceNotify';
var s = document.getElementsByTagName( 'script' )[ 0 ];
s.parentNode.insertBefore( ca, s );
} )();
}
[解决办法]
规范是人定的,你说的规范,在我这里都是要被退回重做的
4行 14行,if后没空格。 我这里要求带空格就退回重做
js 中, ; 本来就是可以被省略的
key 只有json格式才严格规定必须加引号,对于一个对象来说,本来就没严格规定,我这边为了区别 json 和对象的概念,要求对象的key必须不能用引号
楼主强迫症,应该要立刻看心理医生,快回家吃药
[解决办法]
这些好像随便哪些编辑器都能自动处理.
[解决办法]
你觉得不规范是正常的,因为标准不一致;
不过这段代码的确不值得推荐,全局变量太多
[解决办法]
还规范,做好后直接压缩,都是一行了,还哪来缩进。
[解决办法]
谁说没分号就不能压缩的?
即使你写了分号压缩后很多也给去掉了