我最近刚开始学JS,看到cookie这一章的时候,有一个例子怎么也出不来,请高手指教难道onsubmit里面location是不起作用的?
我在location前面加了一句alert(document.cookie);是可以输出的,但是页面不会进行跳转
直接写成onsubmit("window.location.href='12-1.html';")也不会进行跳转
把window去掉也不行,改成self也不行,甚至改成document也不行,href去掉也不行
后面的地址改成绝对位置也不行
莫非是我拼写错误?部分代码如下:<html>
<head>
<title></title>
<style type="text/css">
<!--
.textStyle
{
width:150px;
height:20px;
}
-->
</style>
<script type="text/javascript">
<!--
function setCookie(name,value,expires,path,domain,secure)
{
var curCookie=name+'='+encodeURI(value)+(expires?(';expires='+expires.toUTCString):'')+(path?(';path='+path):'')+(domain?';domain='+domain:'')+(secure?';secure':'');
document.cookie=curCookie;
}
function loginCheck()
{
if (document.form1.username.value=='www' && document.form1.password.value=='1234')
{
var login=true;
var now=new Date();
now.setDate=(now.getDate()+30);
setCookie('login',login,now);
document.location.href='12-1.html';//这句话不起作用
}
}
-->
</script>
</head>
<body>
<form name="form1" action="" method="post" onsubmit="loginCheck();">
<p>
用户名:<input type="text" name="username" class="textStyle" />
</p>
<p>
密 码:<input type="password" name="password" class="textStyle" />
</p>
<p>
<input type="submit" value="提交" />
<input type="reset" value="重置" />
</p>
</form>
</body>
</html>
我在location前面加了一句alert(document.cookie);是可以输出的,但是页面不会进行跳转
直接写成onsubmit("window.location.href='12-1.html';")也不会进行跳转
把window去掉也不行,改成self也不行,甚至改成document也不行,href去掉也不行
后面的地址改成绝对位置也不行
莫非是我拼写错误?部分代码如下:<html>
<head>
<title></title>
<style type="text/css">
<!--
.textStyle
{
width:150px;
height:20px;
}
-->
</style>
<script type="text/javascript">
<!--
function setCookie(name,value,expires,path,domain,secure)
{
var curCookie=name+'='+encodeURI(value)+(expires?(';expires='+expires.toUTCString):'')+(path?(';path='+path):'')+(domain?';domain='+domain:'')+(secure?';secure':'');
document.cookie=curCookie;
}
function loginCheck()
{
if (document.form1.username.value=='www' && document.form1.password.value=='1234')
{
var login=true;
var now=new Date();
now.setDate=(now.getDate()+30);
setCookie('login',login,now);
document.location.href='12-1.html';//这句话不起作用
}
}
-->
</script>
</head>
<body>
<form name="form1" action="" method="post" onsubmit="loginCheck();">
<p>
用户名:<input type="text" name="username" class="textStyle" />
</p>
<p>
密 码:<input type="password" name="password" class="textStyle" />
</p>
<p>
<input type="submit" value="提交" />
<input type="reset" value="重置" />
</p>
</form>
</body>
</html>
解决方案 »
- 哪位老兄能帮忙修改下我的cookie,代码我已经写好了,不知道怎么加到我原有的页面上。
- 如何在onkeydown或者onkeypress中取到key的实际ascii?
- 问下,163信箱中,点击添加附件就加一行输入框,是怎么做的?
- Extjs4.1递归展开树问题
- 我想用客户端技术生成一个理论不会重复的图片文件名放在影藏域里,这样我上传的图片就不会有名字冲突了
- 怎样在页面中播放rm格式的电影?
- 怎么删除对象的某个属性?(详情请进)
- javascript 取得鼠标所在位置的字符?
- js里有没有类似C/C++的位域
- javascript严格模式下立即执行的函数里头的this指向哪里?
- 如何用JQuery获取所有后代节点,内容见内
- js 获得ID 问题
试试这样
<html>
<head>
<title></title>
<style type="text/css">
<!--
.textStyle
{
width:150px;
height:20px;
}
-->
</style>
<script type="text/javascript">
<!--
function setCookie(name,value,expires,path,domain,secure)
{
var curCookie=name+'='+encodeURI(value)+(expires? (';expires='+expires.toUTCString):'')+(path?(';path='+path):'')+ (domain?';domain='+domain:'')+(secure?';secure':'');
document.cookie=curCookie;
}
function loginCheck()
{
if (document.form1.username.value=='www' && document.form1.password.value=='1234')
{
var login=true;
var now=new Date();
now.setDate=(now.getDate()+30);
setCookie('login',login,now);
window.location.href='12-1.html';//这句话不起作用
}
}
-->
</script>
</head>
<body>
<form name="form1" action="" method="post" >
<p>用户名:<input type="text" name="username" class="textStyle" /></p>
<p>密 码:<input type="password" name="password" class="textStyle" /></p>
<input type="button" value="提交" onclick="loginCheck()" />
<input type="reset" value="重置" />
</form>
</body>
</html>
输入错误ORZ
now.setDate=(now.getDate()+30);多打了个等号= =
很奇怪,location无法跳转,但是alert和document.write却能输出