[英]Can anyone help me on how to sort div according to time? js
我想根據 div .inner h6
的日期和時間對這些 html 進行排序。 我嘗試了很多 javascript 並不能成功。 我是 js 新手,請幫忙
<div class="root-history">
<div class="inner sc">
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galle</span><br>
<h6>7/13/2021 8:10:20 PM</h6>
</div>
<div class="inner sc">
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galle</span><br>
<h6>7/13/2021 8:11:55 PM</h6>
</div>
<div class="inner sc">
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galle</span><br>
<h6>7/13/2021 8:10:12 PM</h6>
</div>
<div class="inner sc">
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galle</span><br>
<h6>7/13/2021 8:10:43 PM</h6>
</div>
<div class="inner sc">
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galle</span><br>
<h6>7/13/2021 8:10:34 PM</h6>
</div>
</div>
像這樣的東西?
new Date(a.querySelector("h6").innerText) - new Date(b.querySelector("h6").innerText)
const root = document.getElementById("root"); [...root.querySelectorAll(".inner")] .sort((a, b) => (new Date(a.querySelector("h6").innerText) - new Date(b.querySelector("h6").innerText))).forEach(e => root.appendChild(e));
<div class="root-history" id="root"> <div class="inner sc"> <span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galle</span><br> <h6>7/13/2021 08:10:20 PM</h6> </div> <div class="inner sc"> <span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galle</span><br> <h6>7/13/2021 08:11:55 PM</h6> </div> <div class="inner sc"> <span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galle</span><br> <h6>7/13/2021 08:10:12 PM</h6> </div> <div class="inner sc"> <span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galle</span><br> <h6>7/13/2021 08:10:43 PM</h6> </div> <div class="inner sc"> <span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galle</span><br> <h6>7/13/2021 08:10:34 PM</h6> </div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.