V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
python30
V2EX  ›  Python

Django 后端如何动态设置前端 a 链接的 class 为 select 或 unselect?

  •  
  •   python30 · 5 天前 · 491 次点击

    问个 css 问题。如下图所示:人才信息 pkyP6e0.webp

    就是当前页面的 a 链接 css 不一样 我看了一个他的源代码: pkyPcwV.webp

    就是当首页面的 a 链接 是被选中的 class="select" 其它的链接是:class="unselect"

    我是用 django 做后端,前端 如果根据 cate.slug 来判断的话。那有多少个分类就要写多少个 if 语句了 不知道有什么更简单的功能来实现这个问题? 多谢各位

    2 条回复    2024-06-26 22:50:16 +08:00
    l4ever
        1
    l4ever  
       5 天前
    const allLinks = document.querySelectorAll('a');

    allLinks.forEach(link => {
    link.className = link.title === '人才信息' ? 'select' : 'unselect';
    });
    lybcyd
        2
    lybcyd  
       5 天前
    当前页面的 active slug 可以根据路由来获取,一个判断语句就可以了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   998 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 22:27 · PVG 06:27 · LAX 15:27 · JFK 18:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.