我目前在博客上有两篇帖子。帖子的标记如下(略微删除):
<div class="post audio" id="post_27">
<div class="subpost">
<div class="jp-jplayer">
<!-- Other unimportant code -->
</div>
</div>
</div>
<div class="post audio" id="post_26">
<div class="subpost">
<div class="jp-jplayer">
<!-- Other unimportant code -->
</div>
</div>
</div>
和jQuery:
$(document).ready(function(){
var post_id = $(".jp-player").parents(".audio").attr("id");
$(".jp-jplayer").attr("id", "jp_" + post_id);
$("#jp_" + post_id).jPlayer({
ready: function (event) {
$(this).jPlayer("setMedia", {
m4a: "media link..."
});
},
swfPath: "/feathers/audio/jplayer",
supplied: "m4a",
cssSelectorAncestor: "#jp_container_" + post_id,
wmode: "window",
smoothPlayBar: true,
keyEnabled: true
});
});
我想知道如何使用jQuery将 jp-jplayer DIV的ID设置为与各自的音频父级相同。这一直困扰着我好几个小时,所以非常感谢任何帮助!
答案 0 :(得分:0)
你可以这样做 -
$(".jp-player").prop('id',function(){
return "jp_" + $(this).closest('.audio').prop('id');
})