Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

W3.JS HTML 排序


排序元素

w3.sortHTML(selector)

排序列表

点击按钮按字母顺序排序列表

  • 奥斯陆
  • 斯德哥尔摩
  • 赫尔辛基
  • 柏林
  • 罗马
  • 马德里

示例

<button onclick="w3.sortHTML('#id01', 'li')">排序</button>

<ul id="id01">
  <li>奥斯陆</li>
  <li>斯德哥尔摩</li>
  <li>赫尔辛基</li>
  <li>柏林</li>
  <li>罗马</li>
  <li>马德里</li>
</ul>
亲自试一试 » 带 CSS »

排序表格

点击表头相应地排序表格

名称 国家
Berglunds snabbkop 瑞典
North/South 英国
Alfreds Futterkiste 德国
Koniglich Essen 德国
Magazzini Alimentari Riuniti 意大利
Paris specialites 法国
Island Trading 英国
Laughing Bacchus Winecellars 加拿大

示例

<table id="myTable">
  <tr>
    <th onclick="w3.sortHTML('#myTable','.item', 'td:nth-child(1)')">名称</th>
    <th onclick="w3.sortHTML('#myTable','.item', 'td:nth-child(2)')">国家</th>
  </tr>
  <tr class="item">
    <td>Berglunds snabbkop</td>
    <td>瑞典</td>
  </tr>
  <tr class="item">
    <td>North/South</td>
    <td>英国</td>
    </tr>
  <tr class="item">
    <td>Alfreds Futterkiste</td>
    <td>德国</td>
  </tr>
...
</table>
亲自试一试 » 带 CSS »

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.