当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript 解析url的search方法

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 javascript 解析url的search方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-02-27   浏览: 215 ::
收藏到网摘: n/a

在做UI的时候 ,有时会要解析url的search部分,装了一个实用方法,共享给大家。
复制代码 代码如下:

function searchParse(){
var resultObj = {};
var search = window.location.search;
if(search && search.length > 1){
var search = search.substring(1);
var items = search.split('&');
for(var index = 0 ; index < items.length ; index++ ){
if(! items[index]){
continue;
}
var kv = items[index].split('=');
resultObj[kv[0]] = typeof kv[1] === "undefined" ? "":kv[1];
}
}
return resultObj;
}
//Sample Code
//Url:http://localhost/default.aspx?a=hello&b=kt&c=group
var searchObj = searchParse();
var a = searchObj["a"]; //a==hello
var b = searchObj["b"]; //b== kt
var c = searchObj["c"]; //c== group

如果上面的代码不够好,可以参考下面的文章。
javascript 获取url参数和script标签中获取url参数函数代码
JavaScript URL参数读取改进版

javascript[js]获取url参数的代码 '