警告变量时双弹出不同的值?

Double pop up with different values when alerting a variable?

我正在尝试获取变量的值,并且正在使用警报检查它。

html:

<div class="item">
   <span class="video" data-vimeoid="http://vimeo.com/XXX"></span>
</div>
<div class="item">
   <span class="video" data-vimeoid="http://vimeo.com/YYY"></span>
</div>
<div class="item">
   <span class="video" data-vimeoid="http://vimeo.com/ZZZ"></span>
</div>

jQuery

$(document).on( 'click', '.item:not(.is-expanded)', function() {
  var url = $(this).find(".video").data("vimeoid");
  alert(url);
});

第一次触发 http://vimeo.com/XXX 然后在我点击弹出窗口上的确定后,另一个警报显示 undefined

完整代码在这里:

$(document).on( 'click', '.item:not(.is-expanded)', function() {
    $(".item").removeClass('is-expanded');
    $(".caption").css("display", "block");
    $(".wrapVideo").css("display", "none");
    $("img").fadeIn();
    $(this).addClass('is-expanded');
    $(".is-expanded .caption").removeClass("loaded-caption").css("display", "none");
    $(".is-expanded img").css("display", "none");
    $(".is-expanded .wrapVideo").css("display", "block");
    $("#list").isotope("layout");
    var url = $(this).find(".video").data("vimeoid");
    alert(url);
    var tokens = url.split("/");
    var id = tokens[3];
    var videoSpan =  $(this).find("span.video");
    var iframe = $('<iframe/>', {
            'frameborder' : 0,
            'class' : 'embed-responsive-item',
            'src' : 'http://player.vimeo.com/video/'+ id + '?api=1&player_id=player webkitAllowFullScreen  mozallowfullscreen allowFullScreen'
    });
    videoSpan.replaceWith(iframe);
});

我是这样解决的:

$(document).on( 'click', '.item:not(.is-expanded)', function() {
    $(".item").removeClass('is-expanded');
    $(this).addClass('is-expanded');
    $(".caption").css("display", "block");
    $(".item:not(.is-expanded) img").fadeIn();
    $(".item:not(.is-expanded) .wrapVideo").css("display", "none");
    var videoSpan =  $(this).find("span.video");
    var url = videoSpan.data("vimeoid");
    if(url){
        var tokens = url.split("/");
        var id = tokens[3];
        var iframe = $('<iframe/>', {
                'frameborder' : 0,
                'class' : 'embed-responsive-item',
                'src' : 'http://player.vimeo.com/video/'+ id + '?api=1&player_id=player webkitAllowFullScreen  mozallowfullscreen allowFullScreen'
        });
        videoSpan.replaceWith(iframe);
    } 
    $(".is-expanded .caption").removeClass("loaded-caption").css("display", "none");
    $(".is-expanded img").css("display", "none");
    $(".is-expanded .wrapVideo").css("display", "block");
    $("#list").isotope("layout");
});