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

在线等 !!!location.href 地址有 特殊字符 #怎么办
HTML code
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title>login</title>
    <script type="text/javascript">
        function login(){
            var obj1 = document.getElementById("username");
            var userStr = obj1.value;
            var obj2 = passwordStr = document.getElementById("password");
            var passwordStr = obj2.value;
            var url = "http://localhost:8080/KnowledgeBase/index.html#user="+userStr+"&password="+passwordStr;  
            [color=#FF0000]location.href = encodeURIComponent(url);[/color]
        }
    </script>
</head>
<body>
<form>
    <p>
    <label for="username"></label>
    <input type="text" id="username" name="username">
  </p>
  <p>
    <label for="password"></label>
    <input type="text" id="password" name="password">
  </p>
  <p>
    <INPUT type="button" value="登陆" onClick="login()">
  </p>
</form>
</body>
</html>

为什么我点击提交的时候
地址C:\Users\Chen\Desktop\http://localhost:8080/KnowledgeBase/index.html#user=admin&password=admin
为什么会带上去(C:\Users\Chen\Desktop\)
我只要http://localhost:8080/KnowledgeBase/index.html#user=admin&password=admin地址
如何改!

------解决方案--------------------
不要用encodeURIComponent编码了,浏览器会自动对url进行编码。还有,#后面的字符串在服务器端是获取不到的哦
------解决方案--------------------
必须有应用程序服务器啊,比如将程序部署到iis,你是本机磁盘里直接运行的吧?
------解决方案--------------------
访问页面时使用类似http://localhost的方式。不要使用本地那种直接打开一个文件的方式。试试