在属性选择器中获取当前页面/网址 [英] get current page/url in attribute selector

查看:141
本文介绍了在属性选择器中获取当前页面/网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在CSS中设置一些文本菜单,当该菜单的链接等于当前网址时。但似乎并不奏效。这是一句话:

I am trying to style some text menu in my css, when the link of that menu equals the current url. But doesn't seem to work. This is the sentence:

#pages.tabs ul li a[href$=location]{color:blue !important;}

,其中#pages.tabs ul li 是位于那些链接的菜单列表。我猜想位置包含了css中的当前url。但我甚至不知道这是否只能用css来实现。

, where #pages.tabs ul li is the menu list where are located those links. I guessed the location thing contained the current url in css. But i don't even know if this can be achieved only with css.

非常感谢,

Many thanks in advance,

推荐答案

只能从JQuery中使用 addClass removeClass

Only use addClass or removeClass from JQuery.

Css代码:

Css code:

.liactive{background-color:#3C6EC9;}






Jquery code:


Jquery code:

$(document).ready(function(){

$('ul li').click(function(){
  var items=$('ul li').get();
  for(var i=0;i<items.length;i++)
  $(items[i]).removeClass('liactive');
  $(this).addClass('liactive');
 });

});






我为您制作了这段代码。玩得开心^^
这是你的例子-------->

这篇关于在属性选择器中获取当前页面/网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆