如何使用 javascript 替换或删除这些元素
我已经创建了下面的函数来创建视频元素的负载,但是如何让 javascript 再次删除它或在加载这些元素后替换元素?我还有另外两个类似的函数,它们只是加载不同的视频。我希望当调用其他两个函数之一时这些元素消失,以便可以看到新的视频元素。
function createVideo1(){
//alert("createSmallVideo has been called");
var video = document.createElement("video");
video.setAttribute("id", "VideoElement");
video.setAttribute("src", "videos/surfing with friends.ogv");
video.setAttribute("controls", "");
video.setAttribute("width", "480");
video.setAttribute("height", "300");
document.getElementById("VideoContainer").appendChild(video);
video.play();
}
I've created the function below to create a load of video elements but how can I get javascript to delete it again or replace elements after these have been loaded? I've got another two functions like this that just load different videos. I want these elements to dissapear when either one of the other two function is called, so the new video elements can be seen.
function createVideo1(){
//alert("createSmallVideo has been called");
var video = document.createElement("video");
video.setAttribute("id", "VideoElement");
video.setAttribute("src", "videos/surfing with friends.ogv");
video.setAttribute("controls", "");
video.setAttribute("width", "480");
video.setAttribute("height", "300");
document.getElementById("VideoContainer").appendChild(video);
video.play();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以删除使用此功能创建的当前视频元素。只需在创建新视频元素并插入之前调用它即可。
You can remove the current video element that you created with this function. Just call it before you create a new video element and insert it.
替换
document.getElementById("VideoContainer").appendChild(video);
通过
这种方式,您只需将已有的视频元素替换为新的视频元素即可。
Replace
document.getElementById("VideoContainer").appendChild(video);
With
This way your simply replacing the video element that's already there with a new video element.