javascript取url的参数的方法

时间:2023-03-10 07:55:21
javascript取url的参数的方法
<script type="text/javascript">
function request(paras)
{
var url = location.href;
var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
var paraObj = {}
for (i=0; j=paraString[i]; i++){
paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);
}
var returnValue = paraObj[paras.toLowerCase()];
if(typeof(returnValue)=="undefined"){
return "";
}else{
return returnValue;
}
}
var title = request('title');
var dids = request('did'); show(dids,title);
function show(dids,title){
$.ajax({
url: "http://www.xxx.com/index.php?ac=article&at=read&isajax=1",
type: "get",
data:{did:dids},
error: function(){
alert('Error loading XML document');
},
success: function(data,status){
// var obj = eval('(' + data + ')');
$("#content").html(data);
$("#content img").css("width","100%");
$("#content img").css("height","auto");
// alert(title);
// $("#article_title").html(title);
}
});
} </script>