Javascript 获取URL指定参数
Javascript 获取URL指定参数,想破头了,终于想到了。
给一个URL与一样Name,返回指定参数:
JS Code:
<script type="text/javascript">
var url="http://www.wondershare.com/reviews/reviews-write.html?mypid=54&p=Wondershare&abc=Wondershare+Photo+Recovery&myos=Windows&name=12345&ID=147"
function getUrlArguments(sUrl,sName){
var re = RegExp("(\\?|&)?"+sName+"=([^&]*)")
re.test(url)
return RegExp.$2
}
var s=getUrlArguments(url,"abc");
alert(s)
</script>
正则表达式功能太强大了,超牛,呵呵。。。