javascript - 火狐浏览器 : ReferenceError: event is not defined

标签 javascript

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/

相关文章:

javascript - 如何使用单独的 LocalStorage 拥有单独的 Electron 应用程序实例?

javascript - 使用 jquery 根据输入文本框更改和显示 [删除/添加] 可用选项

javascript - 具有不同功能的提交按钮

javascript - 在express.js中间件请求中获取 "#"之后的url

javascript - 从数组中删除部分

javascript - 如何使用 jquery 将 <br> 的上一个和下一个同级文本与 div 换行?

javascript - 为什么是 $(function(){...})?

javascript - Python Pandas read_excel 和 to_json 日期格式错误

javascript - 如何使用 Angular 从文件加载 Json 对象?

javascript - 普通 JavaScript 中的单击并按住事件