保持活动的点击列表与href [英] stay active on clicking list with href

查看:122
本文介绍了保持活动的点击列表与href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,让点击按钮/列表/锚点保持不同的颜色...这一个是由FANGEL回答,我再次感谢。现在,我对同一个问题有不同的问题。

I had a question about letting clicked buttons/lists/anchors stay in a different colour... This one is answered by FAngel, for which I thank again. Now, I have a different problem regarding the same issue.

http://jsfiddle.net/fxTQL/7/

在这个小提琴,效果是我想要的确切效果,但在我的网站,它不会工作。我想我知道问题是什么,但我不知道如何解决它。我的网站有一个框架,其中的主题/帖子,如果我点击按钮,你可以看到在jsfiddle。所以页面刷新并显示链接。然而,这使得不可能让不同颜色的点击链接。它会自动返回到已经有背景颜色的第一个列表项

In this fiddle, the effect is the exact effect as I want, but, on my website, it won't work. I guess I know what the problem is, but I don't know how to solve it. My site has a frame in which topics/posts are fetched if I click on the buttons which you can see on the jsfiddle. So the page "refreshes" and shows the links. This however, makes it impossible to let the clicked links in a different colour. It goes automatically back to the first list item, which has already a background-color

我如何解决这个问题?

这是我考虑的。

<ul id="quick-index-list">
<li<? if(!$_GET['t']||$_GET['t']=='') echo ' class="active"';?>>
<a target="left" href="left">all</a>
</li>


推荐答案

我看到你使用PHP,检索t变量的值。

I see you're using PHP, so you can retrieve the "t" variable's value.

您可以使用它为 li 选择的元素:

You can use it to assign the "active" class to the li element which was selected:

<ul id="quick-index-list" class="pills slim muted">
<li<? if(!$_GET['t']||$_GET['t']=='') echo ' class="active"';?>>
<a id="qindex-popular" title="alle entries" target="left" href="left.php">alles</a>
</li>
<li<? if($_GET['t']=='tod') echo ' class="active"';?>>
<a id="qindex-today" title="entries van vandaag" target="left" href="left.php?t=tod">vandaag</a>
</li>
<li class="yesterday<? if($_GET['t']=='yes') echo ' active"';?>">
<a id="qindex-yesterday" title="entries van gisteren" target="left" href="left.php?t=yes">gisteren</a>
</li>
<li<? if($_GET['t']=='mix') echo ' class="active"';?>>
<a id="qindex-day" title="willekeurige entries" target="left" href="left.php?t=mix">willekeurig</a>
</li>
</ul>

因此,页面加载的类活动已分配给正确的 li with:

So the class "active" on page load is already assigned to the correct li with:

<? if($_GET['t']=='tod') echo ' class="active"';?> /* default element */

<? if($_GET['t']=='tod') echo ' class="active"';?> /* anoter element */



$ c>,只需使用

when you already have a class on the li, just use

<li class="yesterday<? if($_GET['t']=='yes') echo ' active"';?>">

请务必在类名或类属性之前回显空格。希望它有帮助

Be careful to echo spaces before the class name or the class attribute. Hope it helps

这篇关于保持活动的点击列表与href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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