zoukankan      html  css  js  c++  java
  • JS获得URL参数

    使用JavaScript获得URL在参数值
    方法一:
    function getUrlParam(name) { 
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标參数的正則表達式对象 
        var r = window.location.search.substr(1).match(reg); //匹配目标參数 
        if (r != null) return unescape(r[2]); return null; //返回參数值 
    }
    方法二:

    function GetRequest() {

       var url = location.search;//获取url中"?"符后的字串

       var theRequest = new Object();

       if (url.indexOf("?") != -1) {

          var str = url.substr(1);

          strs = str.split("&");

          for(var i = 0; i < strs.length; i ++) {

             theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);

          }

       }

       return theRequest;

    }


    var Request = new Object();
    Request = GetRequest();

    var 參数1,參数2,參数3,參数N;

    參数1 = Request['參数1'];

    參数2 = Request['參数2'];

    參数3 = Request['參数3'];

    参数N = Request['参数N'];

  • 相关阅读:
    Array
    ie兼容
    webpack----entry
    webpack——html-webpack-plugin
    webpack 报错 path is not defind
    PHPStorm自动压缩YUI Compressor配置
    fly
    Math.max得到数组中最大值
    简单html弹窗
    js中页面跳转(href)中文参数传输方式
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5035875.html
Copyright © 2011-2022 走看看