用if语句注入HTML的Javascript



我正试图创建一个函数,通过javascript注入来显示和隐藏div。该函数在没有if(条件(的情况下完美地注入,例如:$("#video-container").load("include/video.html");,但未能使用if语句正确注入。if语句如何破坏这样的东西?

var show_video_feed_bool = false;
function show_video_feed() {
if (show_video_feed_bool == false) {
$("#video-container").load("include/video.html");
show_video_feed_bool = true;
}
if (show_video_feed_bool) {
document.getElementById("video-container").innerHTML = "";
show_video_feed_bool = false;
}
}

video.html

<div id="container">
<video autoplay="true" id="videoElement">
</video>
</div>
<script>
var video = document.querySelector("#videoElement");
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ video: true })
.then(function (stream) {
video.srcObject = stream;
})
.catch(function (err0r) {
console.log("Something went wrong!");
});
}
</script>

尝试:

show_video_feed_bool = false;
function show_video_feed() {
if (!show_video_feed_bool) {
$("#video-container").load("include/video.html");
} else {
document.getElementById("video-container").innerHTML = "";
}
show_video_feed_bool = !show_video_feed_bool;
}