我是使用Jquery窗口的新手,我只是想问一下,因为我很困惑我是否正确使用了addEventListener和removeEventListener?
当我选择不是第3个标签的标签时,我只想删除DOMContentLoaded
。如何检查eventListener是否已删除?谢谢enter code here
var currentTabIndex = $("#example-tabs").steps("getCurrentIndex").val();
if(currentTabIndex == 2){
AddDomContentLoaded();
}
else{
RemoveDomContentLoaded();
}
function AddDomContentLoaded() {
window.addEventListener("DOMContentLoaded", GetDomContentLoaded(), false);
}
function RemoveDomContentLoaded() {
window.removeEventListener("DOMContentLoaded", GetDomContentLoaded());
}
function GetDomContentLoaded() {
var video = document.getElementById("video");
function successCallback(stream) {
// Set the source of the video element with the stream from the camera
if (video.mozSrcObject !== undefined) {
video.mozSrcObject = stream;
} else {
//video.src = (window.URL && window.URL.createObjectURL(stream)) || stream;
// var binaryData = [];
// binaryData.push(data);
// window.URL.createObjectURL(new Blob(binaryData, { type: "application/zip" }))
video.srcObject = stream;
}
video.play();
}
function errorCallback(error) {
$('[id^="capture"]').hide();
}
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
// Call the getUserMedia method with our callback functions
if (navigator.getUserMedia) {
navigator.getUserMedia({ video: true }, successCallback, errorCallback);
}
}