日期:2014-05-16  浏览次数:20348 次

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>|&nbsp;<a href='https://passport.csdn.net/help/faq'>帮助</a>|&nbsp;<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;