Jquery .click事件没有在arraylist中找到项目

时间:2015-04-11 20:02:48

标签: javascript jquery

我基本上试图让.attr在点击事件中更改HTML文件中的数据属性,但我做错了,因为我收到了“错误404响应 - 找不到文件”点击按钮。谢谢你的帮助。

$(function videoShare() {

    var videoID = ['#video1', '#video2', '#video3', '#video4', '#video5', '#video6'],
        thumbnailID = ['#Redwood-video1', '#Redwood-video2', '#Redwood-video3', '#Redwood-video4', '#Redwood-video5', '#Redwood-video6'],
        youtubeID = ["vA3smKNBGUQ", "SEKIre0wH_8", "17SbQ9BlyGM", "O-4pArq9Tnk", "DnVv2ZkiNGo", "N5sPT12O5YU"],
        youtube = "http://www.youtube.com/embed/",
        trigger = $("body").find('[data-toggle="modal"]');

    var videoEnlarge = function (el) {
        var videoID = el.data('video-id'),
            thumbnailID = el.data('thumbnail-id'),
            youtubeID = el.data('youtube-url');

        trigger.click(function () {
            var theModal = $(this).data("target"),
                videoSRC = $(this).attr("data-video", "youtube-url"),
                videoSRCauto = videoSRC + "?autoplay=1";
            $(theModal + ' iframe').attr('src', videoSRCauto);
            $(".Redwood-videoPopup .close").click(function () {
                $(theModal + ' iframe').attr('src', "");
            });
            // console.log(youtube);
        });

    }

    for (var i = 0; i <= videoID.length; i++) {
        $(videoID[i]).data('video-id', videoID[i]);
        $(videoID[i]).data('youtube-id', youtube + youtubeID[i]);
        $(videoID[i]).data('URL', URL[i]);

        $(videoID[i]).click(function (e) {
            videoEnlarge($(this));
        });
    }

    videoEnlarge($(videoID[0]));

});

HTML

<a href="#" id="expand" data-toggle="modal" data-target="#videoEnlarge" data-video="http://www.youtube.com/embed/vA3smKNBGUQ" data-ga-event='{"category":"see-whats-new", "action":"video", "label":"expand-video"}'><span>expand<span></a>

1 个答案:

答案 0 :(得分:1)

我认为您的问题是,您没有将data-video属性的值分配给videoSRC变量。您只需将data-video属性设置为&#34; youtube-video&#34;然后将jQuery attr()函数的返回值赋给videoSRC

使用

videoSRC = $(this).attr("data-video");

videoSRC = $(this).data("video");

我希望这能解决你的问题。