js解析URL查詢參數

function getQueryStringArgs(){
     var qs = (location.search.length > 0 ? location.search.substring(1):"");

     var args = {};

     var items = qs.split("&");
     var item = null, name = null, value = null;

     for(var i=0; i < items.length; i++){
         item = items[i].split("=");
         name = decodeURLComponent(item[0]);
         value = decodeURLComponent(item[1]);
         args[name] = value;
     }

     return args;
}

遍歷對象屬性code

 

//順序不肯定
var name;

for (name in student) {
    if (typeof student[name] !== "function") {
        document.writeln(name + ":" + student[name]);
    }
}
相關文章
相關標籤/搜索