繁体   English   中英

在jquery-ui中更改活动手风琴的css和父选项卡

[英]Change css of active accordion and parent tab in jquery-ui

我是jquery的新手,所以对如何选择父选项卡或仅在当前手风琴上添加效果感到困惑。 我在php条件下在脚本中编写的任何代码都不会在.ui-widget-header的CSS中进行任何可见的更改,这很可能是因为我没有选择父元素本身。

让我提供必要的代码片段

<div id="tabs">
<ul>
    <li><a href="#tabs-1">Tab 1</a></li>
    <li><a href="#tabs-2">Tab 2</a></li>
    <li><a href="#tabs-3">Tab 3</a></li>
</ul>
<div id="tabs-1">
    <div id="accordion">

       <div> Some content </div>
       <div> 
           <?php  
           //Perform some query
           if (mysqli_num_rows($query)==0)
           //Make background of current accordion, and parent tab red. Add jquery script here
           echo "<script type='text/javascript'> </script>";//No clue what should be within this script, hence blank...
//Probably something like  $("accordion").parent("#tabs").css( background-color: red;background-image: none;)
//OR $(this).parents('div#tabs').css( background-color: red;background-image: none;)
           ?> 
       </div>
       <div>
          2nd accordion. There should be no effect here. 
       </div>
   </div>
   .....

可以在-jsfiddle.net/buKLE/8上获得修改的片段,目前仅是制表符和手风琴。 如有可能,请尝试更改tab1的css,假设手风琴第2节有错误。是否有可能更改该手风琴的颜色,因为所有手风琴都在此处绑定在一起...

您非常接近,您的代码中有两个小错误。

您错过了井号,并采用了错误的遍历方法:

               ↓ only traverses one level up
$("accordion").parent("#tabs")

应该:

   ↓ hash       ↓ traverses upwards, until the selector matches or top is reached
$("#accordion").parents("#tabs")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM