【问题标题】:Changing the active tab background color更改活动选项卡背景颜色
【发布时间】:2014-03-04 06:54:43
【问题描述】:

我正在使用 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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      将此代码添加到您的 CSS 样式中,以更改活动标签的背景颜色

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

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

      【讨论】:

        【解决方案3】:

        我找到了简单的解决方案。点击 li 元素,将元素名称设置为 url 。 形成 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>
        

        【讨论】:

          猜你喜欢
          • 2013-08-03
          • 1970-01-01
          • 2018-06-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-08-06
          相关资源
          最近更新 更多