2013-03-13 91 views
1

我有这个脚本,我想播放名称为'pr_id'的歌曲,我该如何将它写入路径中?谢谢!如何在路径中传递变量

 $(document).ready(function(){ 
      var pr_id = document.getElementById('id') 
      $("#jquery_jplayer_1").jPlayer({ 
       ready: function(){ 
        $(this).jPlayer("setMedia", { 
         mp3:"/sounds/[pr_id].mp3" 
         }); 
         }, 
         swfPath: "js", 
         supplied: "mp3", 
         wmode: "window" 
        }); 
       }); 
+0

你要找的术语是“字符串连接”。 – meagar 2013-03-13 13:22:38

回答

3

像这样:

$(document).ready(function() { 
    var pr_id = document.getElementById('id'); 

    $("#jquery_jplayer_1").jPlayer({ 
     ready: function() { 
      $(this).jPlayer("setMedia", { 
       mp3:"/sounds/" + pr_id + ".mp3" 
      }); 
     }, 
     swfPath: "js", 
     supplied: "mp3", 
     wmode: "window" 
    }); 
}); 

将字符串与变量:),不幸的是,不像一些其他语言就不是那么容易包含在字符串变量,你必须拆分字符串起来有点连接。

0
mp3:"/sounds/"+pr_id+".mp3" 

你可以串连它