jQuery Mobile list view
jQuery Mobile list view
List views in jQuery Mobile are standard HTML lists; ordered (<ol>) and Unordered(<ul>).
List views are a powerful feature in jQuery Mobile. It would make standard unordered or ordered lists more widely applicable. The application method is to add the data-role="listview" attribute to the ul or ol tag. Add a link to each item (<li>) that users can click on:
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="main" class="ui-content"> <h2>有序列表:</h2> <ol data-role="listview"> <li><a href="#">列表项</a></li> <li><a href="#">列表项</a></li> <li><a href="#">列表项</a></li> </ol> <h2>无序列表:</h2> <ul data-role="listview"> <li><a href="#">列表项</a></li> <li><a href="#">列表项</a></li> <li><a href="#">列表项</a></li> </ul> </div> </div> </body> </html>
Running instance »
Click the "Run Instance" button to view the online instance
List style rounded corners and edges, use data-inset="true" attribute setting:
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="main" class="ui-content"> <h2>标准列表:</h2> <ul data-role="listview"> <li><a href="#">列表项</a></li> <li><a href="#">列表项</a></li> <li><a href="#">列表项</a></li> </ul><br> <h2>带有 data-inset="true" 属性的列表:</h2> <ul data-role="listview" data-inset="true"> <li><a href="#">列表项</a></li> <li><a href="#">列表项</a></li> <li><a href="#">列表项</a></li> </ul> </div> </div> </body> </html>
Running instance »
Click the "Run Instance" button to view the online instance
By default, a list item's link automatically turns into a button (data-role="button" is not required). |
list delimited
List items can also be converted into list split items, which are used to organize lists and group list items.
To specify list division, add the data-role="list-divider" attribute to the list item<li> element:
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="main" class="ui-content"> <h2>List Dividers</h2> <ul data-role="listview"> <li data-role="list-divider">欧洲</li> <li><a href="#">德国</a></li> <li><a href="#">英国</a></li> <li data-role="list-divider">亚洲</li> <li><a href="#">中国</a></li> <li><a href="#">印度</a></li> <li data-role="list-divider">非洲</li> <li><a href="#">埃及</a></li> <li><a href="#">南非</a></li> </ul> </div> </div> </body> </html>
Running instance »
Click the "Run Instance" button to view the online instance
If you have an alphabetical list, (such as a phone book) you can configure the delimiters for automatically generated items by setting the data-autodividers="true" attribute on the <ol> or <ul> element:
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="main" class="ui-content"> <h2>我的通讯录</h2> <ul data-role="listview" data-autodividers="true" data-inset="true"> <li><a href="#">Adele</a></li> <li><a href="#">Agnes</a></li> <li><a href="#">Albert</a></li> <li><a href="#">Billy</a></li> <li><a href="#">Bob</a></li> <li><a href="#">Calvin</a></li> <li><a href="#">Cameron</a></li> <li><a href="#">Chloe</a></li> <li><a href="#">Christina</a></li> <li><a href="#">Diana</a></li> <li><a href="#">Gabriel</a></li> <li><a href="#">Glen</a></li> <li><a href="#">Ralph</a></li> <li><a href="#">Valarie</a></li> </ul> <p>data-autodividers="true" 属性通过对列表项文本的首字母进行大写来创建分隔符。</p> </div> </div> </body> </html>
Running instance »
Click the "Run Instance" button to view the online instance
data-autodividers="true" can be configured as delimiters for automatically generated items. By default, the delimited text created is the first capital letter of the list item text. |
More examples
read-only list
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="main" class="ui-content"> <h2>有序列表:</h2> <ol data-role="listview"> <li>列表项目</li> <li>列表项目</li> <li>列表项目</li> </ol> <h2>无序列表:</h2> <ul data-role="listview"> <li>列表项目</li> <li>列表项目</li> <li>列表项目</li> </ul> </div> </div> </body> </html>
Running instance »
Click the "Run Instance" button to view the online instance
How to create a list without links (not a button and not clickable).
Panel
How to insert a panel in the list