<!DOCTYPE html> <htmllang="en"> <head> <metacharset="UTF-8"> <title>Videos</title> </head> <body> <ulclass="videos"> <lidata-time="5:43"> Video 1 </li> <lidata-time="2:33"> Video 2 </li> <lidata-time="3:45"> Video 3 </li> <lidata-time="0:47"> Video 4 </li> <lidata-time="5:21"> Video 5 </li> <lidata-time="6:56"> Video 6 </li> <lidata-time="3:46"> Video 7 </li> <lidata-time="5:25"> Video 8 </li> <lidata-time="3:14"> Video 9 </li> <lidata-time="3:31"> Video 10 </li> <lidata-time="5:59"> Video 11 </li> <lidata-time="3:07"> Video 12 </li> <lidata-time="11:29"> Video 13 </li> <lidata-time="8:57"> Video 14 </li> <lidata-time="5:49"> Video 15 </li> <lidata-time="5:52"> Video 16 </li> <lidata-time="5:50"> Video 17 </li> <lidata-time="9:13"> Video 18 </li> <lidata-time="11:51"> Video 19 </li> <lidata-time="7:58"> Video 20 </li> <lidata-time="4:40"> Video 21 </li> <lidata-time="4:45"> Video 22 </li> <lidata-time="6:46"> Video 23 </li> <lidata-time="7:24"> Video 24 </li> <lidata-time="7:12"> Video 25 </li> <lidata-time="5:23"> Video 26 </li> <lidata-time="3:34"> Video 27 </li> <lidata-time="8:22"> Video 28 </li> <lidata-time="5:17"> Video 29 </li> <lidata-time="3:10"> Video 30 </li> <lidata-time="4:43"> Video 31 </li> <lidata-time="19:43"> Video 32 </li> <lidata-time="0:47"> Video 33 </li> <lidata-time="0:47"> Video 34 </li> <lidata-time="3:14"> Video 35 </li> <lidata-time="3:59"> Video 36 </li> <lidata-time="2:43"> Video 37 </li> <lidata-time="4:17"> Video 38 </li> <lidata-time="6:56"> Video 39 </li> <lidata-time="3:05"> Video 40 </li> <lidata-time="2:06"> Video 41 </li> <lidata-time="1:59"> Video 42 </li> <lidata-time="1:49"> Video 43 </li> <lidata-time="3:36"> Video 44 </li> <lidata-time="7:10"> Video 45 </li> <lidata-time="3:44"> Video 46 </li> <lidata-time="3:44"> Video 47 </li> <lidata-time="4:36"> Video 48 </li> <lidata-time="3:16"> Video 49 </li> <lidata-time="1:10"> Video 50 </li> <lidata-time="6:10"> Video 51 </li> <lidata-time="2:14"> Video 52 </li> <lidata-time="3:44"> Video 53 </li> <lidata-time="5:05"> Video 54 </li> <lidata-time="6:03"> Video 55 </li> <lidata-time="12:39"> Video 56 </li> <lidata-time="1:56"> Video 57 </li> <lidata-time="4:04"> Video 58 </li> </ul> <script> </script> </body> </html>
<script> let li = document.querySelectorAll("li"); let a = Array.from(li).map( item => item); let b = [].map.call(li, item => item); let c = [].map.apply(li, [item => item]); let d = [...li].map( item => item);
<script> let li = document.querySelectorAll("li"); // let a = Array.from(li).map( item => item); // let b = [].map.call(li, item => item); // let c = [].map.apply(li, [item => item]); let d = [...li].map( item => item.dataset.time); console.log(d);
<script> let li = document.querySelectorAll("li"); // let a = Array.from(li).map( item => item); // let b = [].map.call(li, item => item); // let c = [].map.apply(li, [item => item]); let d = [...li].map( item => item.dataset.time) .map( time => { let [min,sec] = time.split(":"); return min * 60 + sec * 1 ; }).reduce( (first,next) => first + next , 0); console.log(d); </script>
最後再將所有的時間算數算出小時、分鐘、秒鐘~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<script> let li = document.querySelectorAll("li"); // let a = Array.from(li).map( item => item); // let b = [].map.call(li, item => item); // let c = [].map.apply(li, [item => item]); let d = [...li].map( item => item.dataset.time) .map( time => { let [min,sec] = time.split(":"); return min * 60 + sec * 1 ; }).reduce( (first,next) => first + next , 0); console.log(d);
let sec = d % 60; let min = (d - sec) / 60; let hour = Math.floor(min / 60);
min %= 60; console.log(`${hour}:${min}:${sec}`); </script>