【发布时间】:2026-02-12 01:05:02
【问题描述】:
它完成了方法中的所有操作(例如,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);
}
}
【问题讨论】:
-
你不是已经问过这个问题了吗? *.com/questions/21894835/how-do-i-splice-my-array
-
另外你怎么知道“我的数组不会拼接”?
标签: javascript html arrays function splice