Gets the get parameter from the URL

Source: Internet
Author: User

1. Geturlparam.js

Define (function () {//url parameter var data, index;        (function init () {data = [];        index = {};        var u = window.location.search.substr (1);            if (U! = ") {var params = decodeuricomponent (u). Split (' & '); for (var i = 0, len = params.length; i < Len; i++) {if (params[i]! = ') {var p = P                    Arams[i].split ("="); if (p.length = = 1 | | (P.length = = 2 && p[1] = = "))                        {//P | p= data.push ([']);                    Index[p[0]] = data.length-1;                    } else if (typeof (p[0]) = = ' undefined ' | | p[0] = = ') {//=c | = data[0] = [p[1]];                        } else if (typeof (index[p[0]) = = ' undefined ') {//C=aaa Data.push ([p[1]]);                    Index[p[0]] = data.length-1;                    } else {//C=AAA Data[index[p[0]]].push (p[1]);             }   }            }        }    })();                return {//get parameter, similar to Request.getparameter () param:function (o) {//o: Parameter name or parameter order try {            Return (typeof (o) = = ' number '? Data[o][0]: data[index[o]][0]);  } catch (E) {}},//Get parameter group, similar to Request.getparametervalues () paramvalues:function (o) {//            O: Parameter name or argument order try {return (typeof (o) = = ' number '? Data[o]: Data[index[o]); } catch (E) {}},//Whether it contains the paramname parameter Hasparam:function (paramname) {return typeof (Paramna me) = = ' String '?        typeof (Index[paramname])! = ' undefined ': false;            },//Get the parameter map, similar to Request.getparametermap () parammap:function () {var map = {};  try {for (var p in index) {map[p] = data[index[p]];        }} catch (e) {} return map; }    }});

2. Require.js configuration

Require.js depends on the JS library path configuration require.config ({paths: {//"jquery-1.12": "). /assets/jqui/external/jquery/jquery "," Jquery-ui ":". /assets/jqui/jquery-ui ",//" jquery ":". /assets/bootstrap/js/jquery-3.3.1.min "," jquery ":". /assets/ckeditor/js/jquery-3.2.1 "," Ckeditor-core ":". /assets/ckeditor/ckeditor ", ' Ckeditor-jquery ':". /assets/ckeditor/adapters/jquery "," Jquery-cookie ":". /assets/js/jquery.cookie "," Bootstrap ":". /assets/bootstrap/js/bootstrap "," Alert ":" Js/lib/alert "," Supersized ":".    /assets/js/login/supersized.3.2.7 "," Url-param ":" Js/util/geturlparam ", ' Image-preview ': ' Js/util/preview '            }, Shim: {' ckeditor-jquery ': {deps:[' jquery ', ' Ckeditor-core ']}, ' Jquery-cookie ': {            Deps: [' jquery ']}, ' bootstrap ': {deps: [' jquery ']}, ' Jquery-ui ': { Deps: [' jquery ']}});

3. Use

Require ([' url-param '], function (urlparam) {         var data = {                Id:URLParam.param ("id"),                Schoolname: Urlparam.param (' Schoolname '),                columnName:URLParam.param (' ColumnName '),                Title:URLParam.param ("title")         };})

  

Gets the get parameter from the URL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.