Firefox 在控制台中显示以下错误:
ReferenceError: event is not defined
引用我的代码,它允许我以全屏模式打开嵌入式 YouTube 视频。
$(document).ready(function () {
$(".vma_overlay").click(function () {
var $videoSrcOriginal = $(event.target).siblings('.vma_iFramePopup').attr("src");
// Check if the embedded youtube url has any attributes appended
// by looking for a '?' in the url.
// If one is found, append our autoplay attribute using '&',
// else append it with '?'.
if ($videoSrcOriginal.indexOf('?') > -1) {
var $videoSrc = $videoSrcOriginal
// when the modal is opened autoplay it
$('#vma_ModalBox').on('shown.bs.modal', function (e) {
// set the video src to autoplay
var $videoSrcAuto = $videoSrc + "&autoplay=1&mute=1";
$("#vma_video").attr('src', $videoSrcAuto);
$('body').addClass("modalyt");
})
} else {
var $videoSrc = $(".vma_iFramePopup").attr("src");
// when the modal is opened autoplay it
$('#vma_ModalBox').on('shown.bs.modal', function (e) {
// set the video src to autoplay
var $videoSrcAuto = $videoSrc + "?autoplay=1&mute=1";
$("#vma_video").attr('src', $videoSrcAuto);
$('body').addClass("modalyt");
})
}
// stop playing the youtube video when modal is closed
$('#vma_ModalBox').on('hide.bs.modal', function (e) {
$("#vma_video").attr('src', $videoSrc);
$('body').removeClass("modalyt");
})
});
});
Firefox 突出显示以下代码行是罪魁祸首:
var $videoSrcOriginal = $(event.target).siblings('.vma_iFramePopup').attr("src");
我在 Chrome、IE 或 Edge 中似乎没有遇到此问题。
我尝试将它们全部放在 CodePen 中:https://codepen.io/CodeChaos/pen/ZPgbJe
最佳答案
将事件添加到函数参数
$(".vma_overlay").click(function (event) {
var $videoSrcOriginal = $(event.target).
关于javascript - 火狐浏览器 : ReferenceError: event is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55402286/