js 获取地址栏?后面的参数,实现文章栏目定位
html:
<div class="box"> <ul> <li id="all">全部文章</li> <li id="category1">name1</li> <li id="category2">name2</li> </ul> <div>
js
实例:www.xxx.com/index/article.html?url=all 获取all
<script> function getRequest() { var url = window.location.search; //获取url中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0; i < strs.length; i ++) { theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]); } } return theRequest; } $url = getRequest(); if(!($url.url)){var init = document.getElementById('all').childNodes;init[0].style.color = 'rgb(35, 178, 148)';}else{ var child;child = document.getElementById($url.url).childNodes;child[0].style.color = 'rgb(35, 178, 148)';} </script>