zoukankan      html  css  js  c++  java
  • js获取url参数

     1 function request(paras) {
     2         var url = location.href;
     3         var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
     4         var paraObj = {}
     5         for (i = 0; j = paraString[i]; i++) {
     6             paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
     7         }
     8         var returnValue = paraObj[paras.toLowerCase()];
     9         if (typeof (returnValue) == "undefined") {
    10             return "";
    11         } else {
    12             return returnValue;
    13         }
    14     }
    15 
    16  
    17 
    18 var facadeInteriorResourceInfoID = request("facadeInteriorResourceInfoID");
    19 
    20 var facadeInteriorImageID = request("facadeInteriorImageID");

     另外一种方式,效率更高些,且更完善(来自JavaScript高级编程):

     1  function getQueryStringArgs() {
     2         var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
     3         args = {},
     4         items = qs.length ? qs.split("&") : [],
     5         item = null,
     6         name = null,
     7         value = null,
     8         i = 0,
     9         len = items.length;
    10 
    11         for (i = 0; i < len; i++) {
    12             item = items[i].split("=");
    13             name = decodeURIComponent(item[0]);
    14             value = decodeURIComponent(item[1]);
    15 
    16             if (name.length) {
    17                 args[name] = value;
    18             }
    19         }
    20 
    21         return args;
    22     }
    23 
    24     //查询字符串为?q=javascript&num=10
    25     var args = getQueryStringArgs();
    26     alert(args["q"]); //"javascript"
    27     alert(args["num"]);//"10"
  • 相关阅读:
    布局管理
    菜单和工具栏
    Hello World,本章学习Qt的基本功能
    PyQt5中文手册
    qemu-kvm使用
    查看内核日志
    tmux快捷键
    vim插件YouCompleteMe安装
    git submodule删除多余模块
    vim ctags
  • 原文地址:https://www.cnblogs.com/futao/p/2525855.html
Copyright © 2011-2022 走看看