我正在嘗試製作我的網站的移動版本,並且jplayer的功能與我的主站點非常相似。播放列表根據您所在的頁面進行更新,除播放列表以外的所有歌曲都將從播放列表中刪除,然後該頁面將動態添加您正在查看的頁面中的歌曲。我的jplayerplaylist刪除功能不起作用
它在我的主頁上正常工作,但我的移動版本(幾乎相同的代碼)無法正常工作。
我設置jplayer_playlist.option("removeTime", 0);
就像jplayer文檔建議的,但它不起作用。這裏有一些我的代碼,所以你可以看到我在做什麼。
function reload()
{
var current = jplayer_playlist.current;
for(var i = 0; i < current; i++)
{
deleteSong(0);
}
var length = theTitles.length;
for(var i = 0; i < (length - 1); i++)
{
deleteSong(1);
}
}
function deleteSong(index)
{
if(!jplayer_playlist.remove(index))
{
console.log("Could not delete it.");
}
}
第一次刪除不顯示錯誤消息,但第二次(以及後面的每次刪除)都沒有。看起來好像它沒有認識到我將removeTime
設置爲0,即使我做了(並且在任何刪除調用之前)。除了removeTime之外,還有什麼其他的jplayer.remove函數依賴於你何時試圖刪除它?
顯然你可以使用回調(在某種方式):http://stackoverflow.com/questions/14105766/jquery-callback-within-the-remove-function – Jared
另外jQuery的UI實際上增加它作爲回調:http://stackoverflow.com/questions/2200494/jquery-trigger-event-when-an-element-is-removed-from-the-dom – Jared
@Jazza我還沒有嘗試過這些答案,但他們依靠未公開的功能。因此,他們可能會在未來的版本中打破。 – Gaurav