zoukankan      html  css  js  c++  java
  • js 接收浏览器的参数值

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>修改页面</title>
    <script type="text/javascript">
    function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    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("&"); //将字符串str 根据 & 分割成多个字符串,并存入数组strs
    /*
    strs[0]="i=1";
    strs[1]="name=james";
    */
    for (var i = 0; i < strs.length; i++) {
    theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
    //theRequest.i=1
    //theRequest.name="james";
    }
    }
    return theRequest;
    }
    //注意:此时是在修改页面里
    window.onload = function () {
    var paras = GetRequest(); //获得url中的参数对象(url中的每个参数都以 该返回值 属性的方式存在)
    //alert(paras.name);
    document.getElementById("txtId").value = paras.i;
    document.getElementById("txtName").value = paras.name;
    //alert(window.location.search);//代表 url 参数字符串
    }
    </script>
    </head>
    <body>
    要修改的班级信息:<br />
    <input type="text" id="txtId" /><br />
    <input type="text" id="txtName" />
    </body>
    </html>

  • 相关阅读:
    DP——背包问题(三)
    堆——练习题
    DP——背包问题(二)
    二叉树的后序遍历(暴力版) 小白菜oj 1034
    树状数组2模板 Luogu 3368
    树状数组1模板 Luogu 3374
    DP——最长上升子序列(n^2与n log n)
    线段树(区间修改)模板题 Luogu 2357 守墓人
    c语言学习摘录
    python 学习摘录
  • 原文地址:https://www.cnblogs.com/cdaq/p/3921588.html
Copyright © 2011-2022 走看看