[英]How to call url in jquery from anchor tag?
I'm working on a web application, Here look at below this jquery codes: 我正在开发一个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,
................
................
Now here is my html code, i want to play this music: 现在这是我的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>
What should i use in this situation? 在这种情况下我应该使用什么?
Did you try the following ? 您尝试了以下吗?
<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>
And then calling $("#lp1").click();
然后调用$("#lp1").click();
with a onClick() method for playing each song. 使用onClick()方法播放每首歌曲。
Or maybe you looked for something like this : 或者,也许您正在寻找这样的东西:
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,
................
................
You can get an url with the following code $("#identifier").attr("href");
您可以使用以下代码$("#identifier").attr("href");
获得网址$("#identifier").attr("href");
Since I don't know the structure of your application I suggest you do a foreach
through all the a
elements 因为我不知道你的应用程序的结构,我建议你做foreach
通过所有的a
元素
Please try this 请尝试这个
$( "a" ).click(function( event ) {
event.preventDefault();
alert($(this).attr('href'));
});
Hope this be of some help 希望这会有所帮助
Happy Learning :) 快乐学习:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.