How to get values in [removed].href? [duplicate]

2019-09-09 06:47发布

This question already has an answer here:

Code:

window.location.href = "Posts?Category=" + sel;

How to get the value in Category page?

1条回答
Viruses.
2楼-- · 2019-09-09 06:58

Try this:

    function getURLParameter(name, urlsearch) {

        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(urlsearch || location.search) || [ , "" ])[1].replace(
                /\+/g, '%20'))
                || null;
    }

    var url = "Posts?Category=1134324";

    alert(getURLParameter('Category', url));

http://jsfiddle.net/kL9DJ/

查看更多
登录 后发表回答