调试一下就会发现
你这里的第二次循环的arr[0]是' username';它的长度是9
多了一个空格,所以不会相等
你这里的第二次循环的arr[0]是' username';它的长度是9
多了一个空格,所以不会相等
解决方案 »
- 求写个js事件
- 请问javascript如何取到HTML中<object>内元素的值?
- prototype.browser.IE为空或者不是对象
- 如何获取当前我在文本编辑器中选中的元素(比如文本框)?
- |zyciis| 还是FireFox和IE的AJAX问题 帮我看一下这一条如何改在IE和FireFox中可以用,AJAX取别一个网页的内容 谢谢
- 开始,学习javascript
- 往table中加入行、列的代码到底该怎么写?我的代码错在哪里?怎么修改才正确?
- 提问
- 求一个模拟的<SELECT>,大家多多帮忙,急需~~~~~
- 大家好看看关于网页在线编辑器的问题???
- 要成为javascript高手应该学习哪些东西?
- javascript方向键有没有支持firefox
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
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");
}
}
<!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>
你这里的第二次循环的arr[0]是 ' username ';它的长度是9
多了一个空格,所以不会相等
============================
不应该是这的问题。