如何使用JavaScript在一个文件夹中处理许多值?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用JavaScript在一个文件夹中处理许多值?相关的知识,希望对你有一定的参考价值。

我想在页面上添加随机音乐播放器。并找到随机的音乐播放器来源。但它只有2首音乐。

如果我在“音频”文件夹中有许多音乐文件超过100个,是否有一些技巧可以处理许多音乐文件?

这是我的JavaScirpt代码。

var lastSong = null; var selection = null; var playlist = ["audio/Boy with luv.mp3", "audio/Mikrokosmos.mp3"]; // List of Songs var player = document.getElementById("audioplayer"); // Get Audio Element player.autoplay = true; player.addEventListener("ended", selectRandom); // Run function when song ends function selectRandom() while (selection == lastSong) // Repeat until different song is selected selection = Math.floor(Math.random() * playlist.length); lastSong = selection; // Remember last song player.src = playlist[selection]; // Tell html the location of the new Song selectRandom(); // Select initial song player.play(); // Start Song

以上代码

var playlist = ["audio/Boy with luv.mp3", "audio/Mikrokosmos.mp3"];

如果播放列表中有很多音乐文件,我想使用like作为功能等添加音乐文件。

我想在页面上添加随机音乐播放器。并找到随机的音乐播放器来源。但它只有2首音乐。如果“音频”文件夹中的音乐文件超过100个,是否有一些技巧可以解决...

答案
具有一个php或其他脚本,会为您提供所有歌曲列表的JSON,并通过AJAX提取,然后从此处填充您的播放列表数组。

以上是关于如何使用JavaScript在一个文件夹中处理许多值?的主要内容,如果未能解决你的问题,请参考以下文章