2016-07-29 56 views
0

我想添加動態數據到這個JavaScript。 那麼如何做到這一點?如何在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 
    }); 
}); 
+3

[追加到陣列(http://stackoverflow.com/questions/351409/appending-to-array) – Tibrogargan

+0

見[Array.prototype.push()](HTTPS的可能重複: //developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/push);如何在JavaScript中添加數組 – cdaiga

+0

您想要添加的數據來自哪裏? – nnnnnn

回答

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 
+0

Tha data is on

+0

告訴我hoow添加到 –