2015-09-28 53 views
0

所以我有這個iframe,每次用戶點擊下一張幻燈片時,都會更新「data-active-video」屬性的值..我試圖檢查「數據活動視頻」具有爲4的值,並且如果它不改變 「下面THX檢查iframe中是否存在動態屬性值

<div class="video-frame"> 
    <iframe width="560" height="315" src="EZF4iS-XEQ8" frameborder="0" id="active_video_player" allowfullscreen="" data-active-video="4"></iframe> 
</div> 

和JS SRC」 value..See代碼:

$('.video-frame').find('iframe').each(function() { 
    if ($(this).attr('data-active-video', '4')) { 
     // alert('yesssss'); 
     $(this).attr('src', 'http://www.somelink.com'); 
    } 
}); 

回答

1

或者你也可以嘗試這樣的。因爲你似乎在使用jQuery。您可以使用數據屬性。無論哪種方式,它都與上面的答案相同。

$('.video-frame').find('iframe').each(function() { 
if ($(this).data('active-video') == '4') { 
    // alert('yesssss'); 
    $(this).attr('src', 'http://www.somelink.com'); 
} 

});