js 获取地址栏?后面的参数,实现文章栏目定位

1
html:
1
2
3
4
5
6
7
<div class="box">
    <ul>
          <li id="all">全部文章</li>
          <li id="category1">name1</li>
          <li id="category2">name2</li>  
    </ul>
<div>

 js

1
实例:www.xxx.com/index/article.html?url=all  获取all
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<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>

  

  

posted @   时光一寸灰  阅读(220)  评论(0编辑  收藏  举报
编辑推荐:
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
阅读排行:
· 为DeepSeek添加本地知识库
· 精选4款基于.NET开源、功能强大的通讯调试工具
· DeepSeek智能编程
· [翻译] 为什么 Tracebit 用 C# 开发
· 腾讯ima接入deepseek-r1,借用别人脑子用用成真了~
点击右上角即可分享
微信分享提示