更改活动选项卡背景颜色

问题描述 投票:0回答:3

我正在使用jstl动态生成选项卡。当我单击选项卡时,CSS样式将应用于动态生成的所有选项卡,而不是选定的选项卡。我的代码是这样的

<sql:setDataSource var="data" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/sample" user="root" password="sample" />
<sql:query dataSource="${data}" var="rs">SELECT DISTINCT component FROM `sample` ORDER BY id DESC LIMIT 7 ;</sql:query>
<ul>
    <li><a href="LandingPage.jsp">Home</a>
    </li>
    <c:forEach var="row" items="${rs.rows}">
        <li> <a href="ComponentPage.jsp?name=${row.component}" id="onlink"> <c:out value="${row.component}" /></a>

        </li>
    </c:forEach>
</ul>

我有这样的css代码

#navbar {
    width: 660px;
}
#navbar #holder {
    height: 31px;
    border-bottom: 1px solid #000;
    width: 1324px;
    padding-left: 25px;
}
#navbar #holder ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
#navbar #holder ul li a {
    text-decoration: none;
    float: left;
    margin-right: 5px;
    line-height: 10px;
    font-family:"Arial Black", Gadget, sans-serif;
    color: #000;
    border: 1px solid #000;
    border-bottom: none;
    padding: 10px;
    width: 105px;
    text-align: center;
    display: block;
    background: #69F;
}
#navbar #holder ul li a:hover {
    background: #F90;
    color: #FFF;
    text-shadow: 1px 1px 1px #000;
}
#holder ul li a#onlink {
    background: #FFF;
    color: #000;
    border-bottom: 1px solid #FFF;
}
#holder ul li a#onlink:hover {
    background: #FFF;
    color: #69F;
    text-shadow: 1px 1px 1px #000;
}

任何人都可以帮助我为所选颜色应用背景颜色?

html mysql css jstl
3个回答
1
投票

您可以使用jquery轻松完成此操作。创建一个具有所需背景颜色的活动类,并使用jQuery方法addClass和removeClass,您可以在单击它时将该类应用于特定选项卡!希望它能帮到你!


0
投票

将此代码添加到您的CSS样式,更改活动选项卡的背景颜色

ul > li.active > a{
/*code here*/
background-color:#cccccc
}

要么

ul > li:active > a{
/*code here*/
background-color:#cccccc
}

0
投票

我找到了简单的解决方案。单击li元素,将元素名称设置为url。如果匹配仅更改背景颜色,则形成获取值的网址。这是一个简单的方式,它可能对某些人有帮助..

<script>
var full_url = document.URL; 
var url_array = full_url.split('=');
var name = url_array[url_array.length-1]; 


$("a:contains("+name+")").css("background-color", "white");



</script>
© www.soinside.com 2019 - 2024. All rights reserved.