JS獲取URL參數方法

 //js get url param
        var getParam = function(name){
                var search = document.location.search;
                var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");
                var matcher = pattern.exec(search);
                var items = null;
                if(null != matcher){
                        try{
                                items = decodeURIComponent(decodeURIComponent(matcher[1]));
                        }catch(e){
                                try{
                                        items = decodeURIComponent(matcher[1]);
                                }catch(e){
                                        items = matcher[1];
                                }
                        }
                }
                return items;
        };
getParam('PId');



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章