如何在JavaScript中动态地向数组添加项?

时间:2016-07-29 06:52:18

标签: javascript jquery

我想在此JavaScript中添加动态数据。 那怎么做呢?

$(document).ready(function(){
        new jPlayerPlaylist({
        jPlayer: "#jquery_jplayer_2",
        cssSelectorAncestor: "#jp_container_2"
    }, [
        {
            title:"Do Pag Mar aur Bhul Ja",
                        mp3:"http://download.apunkabollywood.us/songs/Audio/indian/movies/One Night Stand (2016)/01 - Do Peg Maar - Neha Kakkar @ fmw11.com.mp3",
        },
        {
            title:"Your Face",
            mp3:"http://www.jplayer.org/audio/mp3/TSP-05-Your_face.mp3",
            oga:"http://www.jplayer.org/audio/ogg/TSP-05-Your_face.ogg"
        },
        {
            title:"Cyber Sonnet",
            mp3:"http://www.jplayer.org/audio/mp3/TSP-07-Cybersonnet.mp3",
            oga:"http://www.jplayer.org/audio/ogg/TSP-07-Cybersonnet.ogg"
        }       
    ], {
        swfPath: "musicPlayerfiles/dist/jplayer",
        supplied: "oga, mp3",
        wmode: "window",
        useStateClassSkin: true,
        autoBlur: false,
        smoothPlayBar: true,
        keyEnabled: true
    });
});

1 个答案:

答案 0 :(得分:0)

 U can Write Declare Like Array then you can



var  jPlayerPlaylist=[{
            jPlayer: "#jquery_jplayer_2",
            cssSelectorAncestor: "#jp_container_2"
        }, [
            {
                title:"Do Pag Mar aur Bhul Ja",
                            mp3:"http://download.apunkabollywood.us/songs/Audio/indian/movies/One Night Stand (2016)/01 - Do Peg Maar - Neha Kakkar @ fmw11.com.mp3",
            },
            {
                title:"Your Face",
                mp3:"http://www.jplayer.org/audio/mp3/TSP-05-Your_face.mp3",
                oga:"http://www.jplayer.org/audio/ogg/TSP-05-Your_face.ogg"
            },
            {
                title:"Cyber Sonnet",
                mp3:"http://www.jplayer.org/audio/mp3/TSP-07-Cybersonnet.mp3",
                oga:"http://www.jplayer.org/audio/ogg/TSP-07-Cybersonnet.ogg"
            }       
        ], {
            swfPath: "musicPlayerfiles/dist/jplayer",
            supplied: "oga, mp3",
            wmode: "window",
            useStateClassSkin: true,
            autoBlur: false,
            smoothPlayBar: true,
            keyEnabled: true
        }];
    and the Array Should like This  


jPlayerPlaylist =
    [ObjectcssSelectorAncestor: "#jp_container_2"jPlayer: "#jquery_jplayer_2"__proto__: Object, Array[3]0: Objectmp3: "http://download.apunkabollywood.us/songs/Audio/indian/movies/One Night Stand (2016)/01 - Do Peg Maar - Neha Kakkar @ fmw11.com.mp3"title: "Do Pag Mar aur Bhul Ja"__proto__: Object1: Object2: Objectlength: 3__proto__: Array[0], Object]

You want add one more object U can Push In to  " jPlayerPlaylist " this Array To Use This Flow