zoukankan      html  css  js  c++  java
  • JavaScript------获取url地址中的参数

    转载:
    http://www.cnblogs.com/babycool/p/3169058.html

    //javascript对参数编码解码方法要一致:

    escape()   unescape()
    encodeURI()   decodeURI()  //中文编码
    encodeURIComponent()    decodeURIComponent()  

    $(document).ready(function () {
        //获取地址中的参数(name是字符串)
        function getParameter(name) {
            //正则表达式
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            //location:window的对象
            //search:获取url中的query部分
            //substr:从指定位置开始截取字符串(去掉"?"号)
            var r = window.location.search.substr(1).match(reg);
            //unescape() 函数可对通过 escape() 编码的字符串进行解码。
            if (r != null) return unescape(r[2]); return null;
        }
    
        var str = getParameter("bookId");
        alert(str);
    });
  • 相关阅读:
    高级打字机
    不等数列
    间谍网络
    医院设置
    题目编号生成器
    传纸条
    聪明的打字员
    倒水问题
    八数码难题
    生日蛋糕
  • 原文地址:https://www.cnblogs.com/tianhengblogs/p/6228446.html
Copyright © 2011-2022 走看看