调试一下就会发现
你这里的第二次循环的arr[0]是' username';它的长度是9
多了一个空格,所以不会相等

解决方案 »

  1.   

    【高薪猎头职位】上海外企急聘.NET TeamLeader!简历到Email: [email protected]
    MSN:   [email protected]地点:上海
    职位:TeamLeader(.Net)
    年限:4年以上经验。Title: TeamLeader(.Net)
     
    Responsibilities:
    ·Lead developers to deliver high quality software source code on time
    ·Track the developers' schedule and always beat the deadline
    ·Improve the team's tech standard and increase developers' productivity 
    ·Write design documents and implement the core modules.
    ·Interface with developers and related teams (BA, Tester, QA).
    ·Handle multiple problems and priorities.
    ·Mentor other developersRequirements:
    ·Team leadership and management
    ·Bachelor or above in computer science or equivalent
    ·More than 4 years .Net application experience, at least 2 years experience 
    as a team leader. Experience in multi-national corporations is a plus 
    ·Familiar with standard software development process (e.g. RUP, CMM, etc.)
    ·Knowledge of .NET Framework, OO Methodology, UML and Design Patterns
    ·Strong experience in the latest .Net technologies (.Net 2.0, c#, web 
    service, etc.), experience in java or C++ is a plus.
    ·Good communication & problem solving skills.
    ·Good English both in oral and written
    ·Good project planning and time management skills
    ·Ability to work under a fast paced delivery oriented environment 
      

  2.   

            document.cookie="userid=456";   //生成cookie
            document.cookie="username=song";
            
            var strCookies=document.cookie;
            var arrCookie=strCookies.split(";");
            var userid;
            alert(arrCookie);  //显示cookie
        
            for(i=0;i<arrCookie.length;i++){
              var arr = arrCookie[i].split("=");
      var str = arr[0];
      var reg=/\s/g; 
              var s= str.replace(reg,"");
                if("username"==s)
                {
                    alert("successed");
                    
                }
            }
      

  3.   

    给你个例子看看
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
    <title>cookie处理函数练习(为我所写,非我所想:改善面向对象)</title>
    <script language="JavaScript" type="text/javascript">
    function addCookie(objName,objValue,objHours){//添加cookie
    var str = objName + "=" + escape(objValue);
    if(objHours > 0){//为0时不设定过期时间,浏览器关闭时cookie自动消失
    var date = new Date();
    var ms = objHours*3600*1000;
    date.setTime(date.getTime() + ms);
    str += "; expires=" + date.toGMTString();
    }
    document.cookie = str;
    alert("添加cookie成功");
    }

    function getCookie(objName){//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for(var i = 0;i < arrStr.length;i ++){
    var temp = arrStr[i].split("=");
    if(temp[0] == objName) return unescape(temp[1]);

    }

    function delCookie(name){//为了删除指定名称的cookie,可以将其过期时间设定为一个过去的时间
    var date = new Date();
    date.setTime(date.getTime() - 10000);
    document.cookie = name + "=a; expires=" + date.toGMTString();
    }

    function allCookie(){//读取所有保存的cookie字符串
    var str = document.cookie;
    if(str == ""){
    str = "没有保存任何cookie";
    }
    alert(str);
    }

    function $(m,n){
    return document.forms[m].elements[n].value;
    }

    function add_(){
    var cookie_name = $("myform","cookie_name");
    var cookie_value = $("myform","cookie_value");
    var cookie_expireHours = $("myform","cookie_expiresHours");
    addCookie(cookie_name,cookie_value,cookie_expireHours);
    }

    function get_(){
    var cookie_name = $("myform","cookie_name");
    var cookie_value = getCookie(cookie_name);
    alert(cookie_value);
    }

    function del_(){
    var cookie_name = $("myform","cookie_name");
    delCookie(cookie_name);
    alert("删除成功");
    }
    </script>

    </head>
    <body>
    <form name="myform">
    <div><label for="cookie_name">名称</label><input type="text" name="cookie_name" /></div>
    <div><label for="cookie_value">值</lable><input type="text" name="cookie_value" /></div>
    <div><label for="cookie_expireHours">多少个小时过期</lable><input type="text" name="cookie_expiresHours" /></div>
    <div>
    <input type="button" value="添加该cookie" onclick="add_()" />
    <input type="button" value="读取所有cookie" onclick="allCookie()" />
    <input type="button" value="读取该名称cookie" onclick="get_()" />
    <input type="button" value="删除该名称cookie" onclick="del_()" />
    </div>
    </form>
    <hr />
    </body>
    </html>
      

  4.   

    调试一下就会发现 
    你这里的第二次循环的arr[0]是 ' username ';它的长度是9 
    多了一个空格,所以不会相等
    ============================
    不应该是这的问题。
      

  5.   

    是这样的 cookie 中间是有空格的