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>

  

posted @ 2017-06-15 15:31  滴水穿石!  阅读(279)  评论(0编辑  收藏  举报