Firefox:ReferenceError:未定义事件

问题描述 投票:0回答:1

Firefox在控制台中显示以下错误:

ReferenceError:未定义事件

参考我的代码,它允许我以全屏模式打开嵌入式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

javascript
1个回答
2
投票

将事件添加到函数参数

$(".vma_overlay").click(function (event) {

 var $videoSrcOriginal = $(event.target).
© www.soinside.com 2019 - 2024. All rights reserved.