jquerymobile-10 可折叠内容(Collapsible content)

来源:互联网 发布:送货单软件手机 编辑:程序博客网 时间:2024/05/21 11:16

可能我们在开发中遇到过这样的问题,我们只是看到一个题目或者简单的介绍,然后一点击会在下面展开对应的详细的内容。在jqm中实现这个效果很简单。下面给出一段例子代码:

[html] view plaincopy
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <title>Collapsible Content - 2</title>  
  5. <meta name="viewport" content="width=device-width, initial-scale=1">  
  6. <link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" />  
  7. <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>  
  8. <script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>  
  9. </head>  
  10. <body>  
  11. <div data-role="page" id="first">  
  12.     <div data-role="header">  
  13.         <h1>Collapsible Test</h1>  
  14.     </div>  
  15.     <div data-role="content">  
  16.         <div data-role="collapsible">  
  17.             <h3>First</h3>  
  18.             <p>  
  19.                 Hello World...  
  20.             </p>  
  21.         </div>  
  22.         <div data-role="collapsible">  
  23.             <h3>First</h3>  
  24.             <p>  
  25.                 Hello World...  
  26.             </p>  
  27.         </div>  
  28.         <div data-role="collapsible" data-collapsed-icon="arrow-r" data-expanded-icon="arrow-d">  
  29.             <h3>First</h3>  
  30.             <p>  
  31.                 Hello World...  
  32.             </p>  
  33.         </div>  
  34.         <div data-role="collapsible" data-content-theme="c" data-iconpos="right">  
  35.             <h3>First</h3>  
  36.             <p>  
  37.                 Hello World again...  
  38.             </p>  
  39.         </div>  
  40.     </div>  
  41. </div>  
  42. </body>  
  43. </html>  

页面显示如下:第一个未点开,第二、三、四个都点击开了。



第三个使用了data-collapsed-icon="arrow-r" data-expanded-icon="arrow-d"修改icon。

第四个使用data-content-theme="c"修改显示的主题,使其内容被带有边框的内容包围。 data-iconpos="right"使icon显示在右边。


我们可以将所有带有data-role="collapsible"属性的div,包围在一个<div data-role="collapsible-set">中,使其组成一个整体,但是这样点击其中一个的时候,其他的会自动关闭。这样的显示效果如下: