zoukankan      html  css  js  c++  java
  • 使用js切割URL的参数

    对于一些开发场景,不使用Jsp或freemarker及其其他的模板引擎时,通常通过切割url获得对应的参数,然后通过AJAX与后台交互得到对应的数据

    下面是演示实例:

    test.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>切割URL</title> 
    
    </head> 
    
    <body> 
    <a href="/LMS/test?userId=1">点击</a>
    </body> 
    </html> 

    test2.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>  
    <style type="text/css">  
        select{ width:100px; text-align:center;}  
    </style>  
    <script type="text/javascript">  
    
        window.onload=function(){  
      
            GetRequest();
        };  
        function GetRequest() {
              var fullURL = window.location.href;
              alert(fullURL);
               var url = location.search; //获取url中"?"符后的字串
               var theRequest = new Object();
               alert(url);
               if (url.indexOf("?") != -1) {
                  var str = url.substr(1);
                  strs = str.split("&");
                  alert(strs)
                  for(var i = 0; i < strs.length; i ++) {
                     theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
                      alert(theRequest[strs[i].split("=")[0]]);
                  }
               }
               return theRequest;
            }
    </script>  
    </head>  
      
    <body>  
    
    <p>测试:</p>  
    </body>  
    </html>  
  • 相关阅读:
    SVN报错working copy is not uptodate
    AndroidStudio中获得的VersionCode一直为1和VersionName一直为1.0
    OkHttp
    MockWebServer使用指南(转载)
    Android的Toolbar(含溢出菜单设置[弹出菜单的使用])的使用PopMenu的样式
    8-13笔记-安卓兼容
    自定义Dialog
    安卓圆角Button XML文件
    递归方法扫面文件夹(JAVA控制台程序)
    8月12笔记-安卓文件扫描
  • 原文地址:https://www.cnblogs.com/youcong/p/8966942.html
Copyright © 2011-2022 走看看