我正在开发一个Web应用程序,请看下面这个jquery代码:
$(document).ready(function () {
var myPlaylist = new jPlayerPlaylist({
jPlayer: "#jplayer_N",
cssSelectorAncestor: "#jp_container_N"
}, [
{
title: "<Here is song title>",
artist: "<here is artist>",
mp3: "Here is song URL", //Here i want to call URL from anchor tag..
poster: "images/m0.jpg"
}
], {
playlistOptions: {
enableRemoveControls: true,
................
................
现在这是我的HTML代码,我想播放这首音乐:
<a href="Music/Linkin_park.mp3">Play Linkin park</a>
<a href="Music/Linkin_park2.mp3">Play Linkin park2</a>
<a href="Music/Linkin_park3.mp3">Play Linkin park3</a>
在这种情况下我应该使用什么?
答案 0 :(得分:0)
您是否尝试过以下操作?
<a id="lp1" href="Music/Linkin_park.mp3">Play Linkin park</a>
<a id="lp2" href="Music/Linkin_park2.mp3">Play Linkin park2</a>
<a id="lp3" href="Music/Linkin_park3.mp3">Play Linkin park3</a>
然后使用onClick()方法调用$("#lp1").click();
来播放每首歌曲。
或者你也许找到这样的东西:
var songtoplay = $("#lp1").attr("href");
$(document).ready(function () {
var myPlaylist = new jPlayerPlaylist({
jPlayer: "#jplayer_N",
cssSelectorAncestor: "#jp_container_N"
}, [
{
title: "<Here is song title>",
artist: "<here is artist>",
mp3: songtoplay,
poster: "images/m0.jpg"
}
], {
playlistOptions: {
enableRemoveControls: true,
................
................
答案 1 :(得分:0)
您可以使用以下代码$("#identifier").attr("href");
由于我不知道您的应用程序的结构,我建议您通过所有foreach
元素进行a
答案 2 :(得分:0)
请试试这个
$( "a" ).click(function( event ) {
event.preventDefault();
alert($(this).attr('href'));
});
希望这会有所帮助
快乐学习:)