How to get the query string by javascript?

前端 未结 10 1602
深忆病人
深忆病人 2020-11-27 03:36

How to extract the query string from the URL in javascript?

Thank you!

10条回答
  •  不知归路
    2020-11-27 03:53

    You can use this Javascript :

    function getParameterByName(name) {
        var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
        return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
    }
    

    OR

    You can also use the plugin jQuery-URL-Parser allows to retrieve all parts of URL, including anchor, host, etc.

    Usage is very simple and cool:

    $.url().param("itemID")
    

    via James&Alfa

提交回复
热议问题