[英]Nothing happening on clicking on close button in newly inserted variable- block
[英]jplayer clicking play nothing happening
我目前正在與jPlayer合作,將一些聲音片段添加到我的網站,但是,當我單擊播放時,什么也沒發生...該頁面只是重新加載,就像我單擊了一個鏈接一樣,下面是我的HTML和我的javascript,以及修改過的DOM。
$("#jquery_jplayer").jPlayer({
ready: function (event) {
$('.voice').click(function(e) {
$(this).jPlayer("setFile", $(this).attr('rel')).jPlayer("play");
e.preventDefault();
});
},
solution: "flash, html", // Flash with an HTML5 fallback.
swfPath: "/media/js/jPlayer/",
wmode: "window"
});
});
<li><a href="" rel="<?php echo base_url(); ?>media/uploads/audio/<?php echo $candidate_audio['url']; ?>" class="voice">Play Voice Over</a></li>
閃光燈架
<div id="jquery_jplayer"></div>
在domReady上也進行了更改。
<div id="jquery_jplayer" style="width: 0px; height: 0px;">
<img id="jp_poster_0" style="width: 0px; height: 0px; display: none;">
<object width="1" height="1" id="jp_flash_0" data="/media/js/jPlayer/Jplayer.swf" type="application/x-shockwave-flash" style="width: 0px; height: 0px;">
<param name="flashvars" value="jQuery=jQuery&id=jquery_jplayer&vol=0.8&muted=false">
<param name="allowscriptaccess" value="always">
<param name="bgcolor" value="#000000">
<param name="wmode" value="window">
</object>
</div>
自從我使用jPlayer以來已經有一段時間了,但是我認為這一行: $(this).jPlayer("setFile"...
是問題。由於您是在點擊處理程序中執行this
, this
可能指向錯誤的元素,我會嘗試這樣做:
$("#jquery_jplayer").jPlayer({
ready: function (event) {
var $this = $(this);
$('.voice').click(function(e) {
$this.jPlayer("setFile", $(this).attr('rel')).jPlayer("play");
e.preventDefault();
});
},
solution: "flash, html", // Flash with an HTML5 fallback.
swfPath: "/media/js/jPlayer/",
wmode: "window"
});
這正是它為我工作的方式。 請注意第一行分配了單擊處理程序以阻止單擊鏈接的默認行為...
$(document).ready(function(){
$('[class^="jp-"]').click(function (e) { e.preventDefault(); });
$("#jquery_jplayer").jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {
mp3: "/music/mySong.mp3"
});
},
swfPath: "/jPlayer/js",
supplied: "mp3",
volume: 0.6
});
});
您可以嘗試以下方法。 preventDefault()
應該是函數中的第一項...
$(document).ready(function(){
$("#jquery_jplayer").jPlayer({
ready: function (event) {
$('.voice').click(function(e) {
e.preventDefault(); // <-- first item in this function
$(this).jPlayer("setFile", $(this).attr('rel')).jPlayer("play");
});
},
solution: "flash, html", // Flash with an HTML5 fallback.
swfPath: "/media/js/jPlayer/",
wmode: "window"
});
});
另請注意,在您的原始帖子中,您已經對SO進行了簡單的錯字或編程錯誤。 還有一組右括號, });
或者您放錯位置/未放置初始document.ready
行。
$("#jquery_jplayer").jPlayer({
ready: function (event) {
$('.voice').click(function(e) {
$(this).jPlayer("setFile", $(this).attr('rel')).jPlayer("play");
e.preventDefault();
});
},
solution: "flash, html", // Flash with an HTML5 fallback.
swfPath: "/media/js/jPlayer/",
wmode: "window"
});
}); // <--- remove extra closing brackets
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.