它完成方法中的所有操作(例如alert / div加载),但拼接不起作用。所以我要做的是当用户点击“删除”按钮时,该特定视频将从阵列中删除。
代码:
function updateFavourite(video) {
document.getElementById("favourite").onclick = function () {
blacklist[video["id"]] = true;
myfavourite.push(video);
var html =
"<input class='removeButton' value='Remove' type='button' />" +
"<li class=\"saved\">" +
"<img class= \"img-rounded\" src=\"{0}\"/>" +
"<p><b title=\"{2}\"><a class=\"extendedLink\" href=\"javascript:watchHistoricVideo(\'{1}\');\"><span></span>{2}</a></b><br>" +
"by {3}<br>" +
"{4} | {5} views</p>" +
"</li>";
$("#myfavourite").prepend(html.format(video["thumbnail"],
video["id"],
video["title"],
video["uploader"],
video["length"],
video["views"]));
$("#myfavourite .removeButton").click(function () {
myfavourite.splice(video, 1);
setVideoF(video);
alert("Removed");
document.getElementById("myfavourite").innerHTML = '<div id="myfavourite"></div>';
$("#loadFavourite").trigger('click');
});
setVideoF(video);
}
}
答案 0 :(得分:3)
答案 1 :(得分:0)
如果您只想删除video
对象,可以先执行以下操作,因为您需要先在数组中找到它的索引(如所说的doodeec)...
function Remove(arr, obj) {
var index = arr.indexOf(obj);
if (index != -1) {
arr.splice(index, 1);
} else {
throw new Error("Not in array")
}
};
只需拨打Remove(myfavourite, video);
即可对其进行排序。