"Python Project Combat" BBS Forum (4) Try to beautify the page

Source: Internet
Author: User


Page beautification--The selected plate becomes gray


Using tags <li class= "active" > </li>

Need to put the displayed plate name element, addclass ("active")

Then we need to find out which plate name is currently displayed.

The plate display is based on the plate ID to design the URL, that by obtaining the current page URL of the path can find which plate is

The variable used is--{{Request.path}}

To find the expression that matches the label: $ ("#navbar a[href= ' {{Request.path}} ']") [0], which can be tested by the browser debug mode console


Test steps:

>$ ("#navbar a") #匹配出这么多标签, placed in a list [<a href= "/" > General discussion Area </a> <a href= "/CATEGORY/1 /">DOTA1</A>, <a href="/category/2/">DOTA2</A> <a href="/category/3/">LOL</A> <a href= "/category/4/" > StarCraft </a> <a href= "./fixe ..." >...</A> <a href> in single </a> <a href> late </a> <a href> auxiliary </a>]
>$ ("#navbar a[href= '/category/1/']") #匹配到/category/1/label [<a href= "/category/1/" >DOTA1</A>]
$ ("#navbar a[href= '/category/1/']") [0] #取出list里面的第一个元素, HTML element
>var menus = $ ("#navbar a[href= '/category/2/']") [0] #对第一个元素赋值给对象undefined >$ (menus). Parent () #获得对象menus的父标签 [<li>...</li>]


#在父标签里面加入 class= "Active" $ (menus). Parent (). addclass ("active"); #在其它同胞标签里面去除 class= "Active" $ (menus). Parent (). siblings (). Removeclass ("active");



The final implementation method:

<script type= "Text/javascript" > $ (document). Ready (function () {var menus = $ ("#navbar a[href= ' {{RE            Quest.path}} '] ") [0];            $ (menus). Parent (). addclass ("active");            $ (menus). Parent (). siblings (). Removeclass ("active");        Console.log (menus); }) </script>




This article is from the "Seeworld" blog, make sure to keep this source http://depops2016.blog.51cto.com/4205997/1764259

Python project actual combat BBS Forum (4) try page beautification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.