我已經創建了一個div,我想用一個不同的嵌入式視頻來填充,這個視頻是根據用戶點擊某個div下面的一系列鏈接中的哪個鏈接。目前,該功能僅適用於列表中的頂部鏈接。點擊第一個鏈接下的任何鏈接都不會產生任何效果。這裏的JS:jQuery:如何綁定同一個類的多個元素?
$(document).ready(function(e){
$('a.videoBoxLinks').bind('click',function(e){
var vidUrl = $(this).attr('href');
var vidBox = $(this).prev('.videoBox');
vidBox.html('<iframe src="' + vidUrl + '" width="400" height="300" frameborder="0"></iframe>');
e.preventDefault(); //stops the browser click event
});
});
和HTML
<div class="videoBox">
<h1>default content to be replaced</h1>
</div>
<a class="videoBoxLinks" href="videoURL1">Test 1</a></br> <!--this one works-->
<a class="videoBoxLinks" href="videoURL2">Test 2</a> <!--this one doesn't-->
因此,如果你之前,首先單擊第二個鏈接,但仍然什麼都不做? – 2011-04-20 04:46:28