表单提交后输出的信息乱码,为什么呢?

chuanyuzhiwai 2012-02-24 06:06:43
第一个网页的HTML代码为:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>表单</title>

</head>
<form name="myform" method="get" action="next.html">
姓名:<input type="text" name="username" /><br />
性别:<input type="radio" name="sex" value="男" />男  
<input type="radio" name="sex" value="女" />女<br />
<input type="submit" name="submit" value="提交" /> 
<input type="reset" name="reset" value="重置" /><br />
</form>
<body>
</body>
</html>

接收表单信息的网页代码为:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>接收用户数据</title>
<script type="text/javascript" language="javascript">
var currenturlsearch=location.search;
currenturlsearch=currenturlsearch.substring(1);
var arr=currenturlsearch.split("&");
if(arr.length<2)
{
alert("输入信息不完整!请重新输入!");
history.back();
}
arrname=arr[0].split("=");
document.write(arrname[1]+"<br/>");
arrsex=arr[1].split("=");
document.write(arrsex[1]);
</script>
</head>

<body>
<form name="myform">
<input type="button" value="后退" onclick="history.back()" />
<input type="button" value="前进" onclick="history.forward()" />
直接跳转到第<input type="text" name="gos" value="-1" size="3" />页<input type="button" value="确定" onclick="history.go(myform.gos.value)" />
</form>
</body>
</html>
大家帮着解决下吧,难道是表单提交后已经加密了?
...全文
141 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
我爱荤菜 2012-02-24
  • 打赏
  • 举报
回复
顶起,好问题!
似梦飞花 2012-02-24
  • 打赏
  • 举报
回复
类似于这样
<script type="text/javascript">
function ss(){
window.location.href="a.html?name="+encodeURIComponent(document.forms[0].elements[0].value);
}
</script>
</head>

<body>
<form>
<input type="text"><input type="button" onclick="ss()">
</form>
</body>
a页面则可以
<script type="text/javascript">
function init(){
var a=window.location.search;
a=a.substring(1,a.length);
alert(decodeURIComponent(a));
}
</script>
</head>

<body onload="init()">
</body>试试
似梦飞花 2012-02-24
  • 打赏
  • 举报
回复
如果提交的内容保存在了a变量里用encodeURIComponent(a)作为要传递的内容 然后在接收的页面decodeURIComponent()下试试 不知行不行

87,989

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧