如何在window.location.href中获取值?

时间:2013-11-21 09:26:36

标签: javascript javascript-events location-href

代码:

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

如何在分类页面中获取值?

1 个答案:

答案 0 :(得分:0)

试试这个:

    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/