更改 jquery 移动可折叠集上的文本颜色


如何

处理/更改折叠和展开状态的标题中的文本颜色?谢谢!

您可以在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>

希望这对;)有所帮助

最新更新