2013-08-27 33 views
0

在我當前的項目中有一個HTML5視頻。我用這個視頻js插件。現在我想在點擊播放按鈕時增加(不是全屏)視頻大小。使用隱藏div的jquery查找最近的視頻標籤id

HTML

<video id="big-72_html5_api" class="vjs-tech" data-setup="{ "controls": true,"autoplay": false, "loop": false, "preload": "true" }" preload="true"> 
<div></div> 
<div class="vjs-poster" tabindex="-1" style="display: none;"></div> 
<div class="vjs-text-track-display"></div> 
<div class="vjs-loading-spinner" style="display: none;"></div> 
<div class="vjs-big-play-button" aria-live="polite" tabindex="0" aria-label="play video"> 
<div class="vjs-control-bar"> 

我在<div class="vjs-big-play-button"上點擊事件加入到找上視頻標籤<video id="big-72_html5_api"的ID,請參見下文

jQuery的

$("#user-table").on('click','.vjs-big-play-button', function() { 
    var closest_video_id = $(this).closest("video").find(".vjs-tech").attr("id"); 
    alert(closest_video_id); 
}); 

戲按鈕在點擊時進入隱藏模式。參見下文

當點擊播放按鈕

<div class="vjs-big-play-button" aria-live="polite" tabindex="0" aria-label="play video" style="display: none;"> 

我需要幫助找到視頻標籤ID時,點擊播放按鈕。 對不起,我的英語不好。

回答

0

您的HTML代碼不完整嗎?視頻標籤缺少結束標記</video>

我假設divs是視頻標籤的兄弟,所以你可以使用siblings-selector而不是最接近的,它遍歷dom-tree。此外,如果類vjs-tech是視頻標籤的類,則可能不需要查找部分。 Depents如果你有多個視頻標籤,在這種情況下,你可以做

var closest_video_id = $(this).siblings("video.vjs-tech").attr("id"); 
+0

謝謝您的comments.''缺少這裏,但不是在我的代碼。讓我試試你的代碼。 – user2603482

+0

謝謝,它的工作。 – user2603482