zoukankan      html  css  js  c++  java
  • js怎样把URL链接的参数截取出来

    有时候,A页面参数需要传递到B页面,则把参数拼接到跳转B页面的url上,这时怎样在另一个页面截取A页面传递的参数呢,主要代码如下

    /**
    * 获取指定的URL参数值 URL:http://www.quwan.com/index?name=tyler 参数:paramName URL参数
    * 调用方法:getParam("name") 返回值:tyler
    */
    function getParam(paramName) {
    paramValue = "", isFound = !1;
    if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
    arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
    while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
    }
    return paramValue == "" && (paramValue = null), paramValue
    }

    调用时,

    A页面:传递参数

    //使用方法
    var hrefs='www.baidu.com?classId'=11111'&examId'=1202;

    location.href = hrefs;

    B页面 获取参数
    var classIds = getParam('classId');
    var examIds = getParam('examId');

  • 相关阅读:
    <frame>、<iframe>、<embed>、<object> 和 <applet>
    xss攻击
    回流 和 重绘
    defer 和 async 的区别
    从输入URL到浏览页面的过程
    webkit vs v8
    缓存
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/lvxisha/p/11525983.html
Copyright © 2011-2022 走看看