2014-01-27 56 views
1

我正在使用Jquery Mobile(1.4)開發跨平臺應用程序。擴展時更改可摺疊列表標題顏色

我希望能夠在摺疊時展開摺疊列表標題的背景顏色,並在摺疊時將其重新設置。

任何人都可以讓我知道如何更改「可摺疊列表標題」的背景顏色。

如果我們能夠通過純CSS來做到這一點會更好。

預先感謝您。

+0

後您的標記,你試過什麼已經 – monners

+0

我敢肯定,適當的類添加/刪除已經當元素被摺疊或摺疊出來 - 所以去拿一個DOM檢查器,找出這些類是什麼,然後簡單地使用它們來以不同的方式在兩種狀態下格式化元素。 – CBroe

+0

CBroe,我曾嘗試過,但無法看到我在以下課程中所做的更改: - 「ui-collapsible-heading ui-collapsible-heading-collapsed」和「.ui-collapsible-collapsed + .ui-collapsible :not(.ui-collapsible-inset)> .ui-collapsible-heading .ui-btn'。我想要列表標題的背景顏色在列表摺疊時更改 – BetRob

回答

1

改變顏色如你所願

.ui-collapsible-heading-collapsed > .ui-collapsible-heading-toggle{ 
    background:red; 
} 

.ui-collapsible-heading-toggle{ 
    background:yellow; 
} 

DEMO

+0

謝謝Kawinesh。雖然我不想要表格。但是,是的,「可摺疊列表標題」變成黃色,這就是我想要簡單使用** CSS **。因爲在我的應用程序中會有多個可摺疊列表,我不想使用JavaScript函數處理顏色變化。我嘗試在這些類中修改CSS:ui-collapsible-heading ui-collapsible-heading-collapsed,'.ui-collapsible-collapsed + .ui-collapsible:not(.ui-collapsible-inset)> .ui JQM 1.4 CSS中的可摺疊標題.ui-btn',但我無法使用它 – BetRob

+0

@BetRob在可摺疊集中使用了圖標。 –

+0

是的,擴大和摺疊的圖標。 – BetRob

0

HTML

<div data-role="collapsible" id="clp" class="width70" data-mini="true"> 
<h3 style="width: 120px"> 
        Search 
       </h3> 

<div> 
    <table data-role='table' id='tblSearch' data-mode='reflow' class='my-custom-breakpoint'> 
     <thead id="tbl1"> 
      <tr> 
       <th>HEADER1</th> 
       <th>HEADER2</th> 
       <th>HEADER3</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
       <td> 
        <input type="text" id="txtInsuredName" name="txtInsuredName" /> 
       </td> 
       <td> 
        <input type="text" id="txtPolicy" name="txtPolicy" /> 
       </td> 
       <td> 
        <input type="text" id="txtOT" name="txtOT" maxlength="10" /> 
       </td> 
      </tr> 
     </tbody> 
    </table> 
</div> 

JQUERY

$('#clp').bind('expand', function() { 
    $('#tbl1').addClass('greybackcolor'); 
    }).bind('collapse', function() { 
    $('#tbl1').removeClass('greybackcolor'); 
}); 

CSS

.width70 { 
width: 85%; 
} 
.greybackcolor { 
background: yellow; 
} 
@media (min-width: 400px) { 
/* Show the table header rows and set all cells to display: table-cell */ 
    .my-custom-breakpoint td, .my-custom-breakpoint th, .my-custom-breakpoint tbody th,  .my-custom-breakpoint tbody td, .my-custom-breakpoint thead td, .my-custom-breakpoint thead th { 
    display: table-cell; 
    margin: 0; 
} 
/* Hide the labels in each cell */ 
.my-custom-breakpoint td .ui-table-cell-label, .my-custom-breakpoint th .ui-table-cell-label { 
    display: none; 
    } 
} 

請找工作演示:DEMO

+0

謝謝Rohit!但是,我想要實現的是,當此列表展開時,我想更改標題的背景色以進行更改,並且在摺疊時它應該恢復原樣。 – BetRob

+0

已更新我的演示鏈接,請檢查並告訴我是否需要任何幫助 –

+0

Rohit by headers我的意思是可摺疊列表標題,當「+」符號更改爲「 - 」時,我們希望可摺疊列表的背景改變。 「在列表中。謝謝 – BetRob