jquery获取URL参数

<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript">
(function($){
    $.getUrlParam = function(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r!=null) return unescape(r[2]); return null; 
    }
})(jQuery);
$(function(){
    $('#url').click(function(){
        alert(window.location.href);
    })
    $('#param').click(function(){
        alert($.getUrlParam('wd'));
    })
})
</script>
</head>

<body>
<button id="url">jquery获取url</button>
<button id="param">jquery获取url参数</button>
</body>
</html>

  

posted @ 2012-06-19 19:15  firesnow  阅读(522)  评论(0编辑  收藏  举报