0

我正在将 JPlayer 用于网站。现在,我想从带有路径和艺术家姓名的表中创建播放列表。现在我所做的是将表格添加到页面中,现在,使用 forEach 我尝试读取路径并将其添加到播放列表中。但不知何故我很困惑..看看这是我用来抓取路径的代码,它工作正常

    <script type="text/javascript">
    $(document).ready(function () {
        $('#songsPathGridView tr').each(function () {
            if (!this.rowIndex) return; // skip first row
            var path = this.cells[0].innerHTML;
            alert(path);

        });
    });
</script>

现在这是我拥有的播放列表(硬编码值)。现在,如果它是 html 或其他内容,我可以将路径附加到它,但由于它是 jquery 代码,请告诉我该怎么做.. 这是播放列表代码

  <script type="text/javascript">
    $(document).ready(function () {
        var songName = "Song1";
        var theArtist = "The Artist";
        var myPlaylist = [
            {
                mp3: 'music/Mad.mp3', oga: 'mix/1.ogg', title: songName, artist: theArtist,
            },
          {
              mp3: 'mix/EssentialViolet.mp3', oga: 'mix/2.ogg', title: songName, artist: theArtist, cover: 'mix/2.jpg'
          }
        ];
        $('body').ttwMusicPlayer(myPlaylist, {
            autoPlay: false,

            jPlayer: {
                swfPath: '../plugin/jquery-jplayer' //You need to override the default swf path any time the directory structure changes
            }
        });
    });
</script>

不知何故,我想获取文件路径并动态添加它。请帮忙,谢谢。

4

1 回答 1

1

我想查看您用于表格的 HTML 代码,因为它会影响构造,但基本上这种方法应该有效:

$(document).ready(function () {

    var myPlaylist = [{}]; // Empty object to push into

    $('#songsPathGridView tr').each(function () {
        if (!this.rowIndex) return; // skip first row
        // Push each row's data into the myPlaylist variable
        // Expects MP3 path at column 0, title at column 1, artist at column 2
        myPlaylist.push( { mp3: this.cells[0].innerHTML, title: this.cells[1].innerHTML, artist: this.cells[2].innerHTML } );
    });

    $('body').ttwMusicPlayer(myPlaylist, {
        autoPlay: false,
        jPlayer: {
            swfPath: '../plugin/jquery-jplayer' //You need to override the default swf path any time the directory structure changes
        }
    });

});
于 2013-05-02T17:10:55.223 回答