function querystring(){ this.params = new Object(); this.initialize = function(){ var param=this.paramstring(); if(param.length == 0) return; if(param.substring(0,1)=='?'){ param=param.substring(1); } param = param.replace(/\+/g, ' '); var args = param.split('&'); for (var i=0;i<args.length;i++){ var value; var pair = args[i].split('='); var name = unescape(pair[0]); if (pair.length == 2) value = unescape(pair[1]); else value = name; this.params[name] = value; } }; this.get = function(key, defvalue){ return this.params[key]==null?defvalue:this.params[key]; }; this.paramstring = function(){ var col=document.getElementsByTagName("script"); var jsrc=col.item(col.length-1).src; var i=jsrc.indexOf("?"); var words=jsrc.substr(i+1,jsrc.length); return(words); }; this.initialize(); } var q = new querystring(); var a = q.get('a','defaultvalue'); //defaultvalue是默认值 var b = q.get('b','defaultvalue'); //defaultvalue是默认值
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <script type="text/javascript" src="a.js?a=baidu&b=google"></script> <title>无标题文档</title> </head> <body> <!-- js运行结果将得到: a=baidu b=google --> </body> </html>
阅读:932
评论:0
゛. - 看過世间最冷漠滴眼神, 爱過⒈生最无缘滴人﹎
该页面还没有任何评论,赶快占个沙发吧!