2012-10-12 40 views
1

如何解决/更改折叠和展开状态的标题中的文本颜色?谢谢!更改jQuery移动可折叠设置上的文字颜色?

+2

添加类和关闭 –

+0

当div有以下属性,当它展开删除类:data-collapsed =“false”,当它折叠时,它的data-collapsed =“true”。 –

+0

谢谢,但任何代码示例? – harp

回答

0

您可以手动更改在collapseexpand事件的崩溃/扩展头部的颜色:

$("#mycollapsible").bind('expand', function() { 

    // Change color here 

}).bind('collapse', function() { 

    // Change color here 

}); 

其中#mycollapsible是你的可压缩集的ID。


全部工作示例:

<!DOCTYPE html> 
<html> 
<head> 

<meta name="viewport" content="width=device-width, initial-scale=1"> 

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> 
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script> 

<script> 

function toggle_color() { 
    $("#mycollapsible .ui-icon-arrow-r").parent().find(".ui-btn-text").css('color', "red"); 
    $("#mycollapsible .ui-icon-arrow-l").parent().find(".ui-btn-text").css('color', "blue"); 
} 

$(function() { 

    // Initialization 
    toggle_color(); 

    // Binding collapse/expand event 
    $("#mycollapsible").bind('expand', function() { 
     toggle_color(); 
    }).bind('collapse', function() { 
     toggle_color(); 
    }); 
}); 

</script> 
</head> 


<body> 
<div data-role="page"> 
    <div data-role="header"> 
    <h1>My Title</h1> 
    </div> 
    <!-- /header --> 

    <div data-role="content"> 
    <p>Hello world</p> 

    <div id="mycollapsible" data-role="collapsible-set" data-iconpos="right" data-collapsed-icon="arrow-r" data-expanded-icon="arrow-l"> 
     <div data-role="collapsible" data-collapsed="true" > 
     <h3>Section 1</h3> 
     <p>I'm the collapsible set content for section 1.</p> 
     </div> 
     <div data-role="collapsible" data-collapsed="true"> 
     <h3>Section 2</h3> 
     <p>I'm the collapsible set content for section 2.</p> 
     </div> 
    </div> 


    </div> 
    <!-- /content --> 

</div> 
<!-- /page --> 

</body> 

</html> 

希望这有助于;)

+0

非常感谢! – harp

+0

您的欢迎伙伴;)。 – Littm

+0

这工作得非常好,谢谢!还有一个问题 - 在iPhone上触摸标题以打开其内容时,该栏变为蓝色。有没有办法访问或关闭?谢谢。 – harp