0
我需要返回所選視頻拇指li的當前值,所以如果我點擊第二個li返回id是2等。目前有返回2,如果我選擇第一和第二李。我最終需要根據選定的li開啓不同的功能。如果這完全是爲了實現這一目標,請指出我的正確領導。jQuery/XML從一個xml節點返回當前目標li id個別功能
我想要實現的是:我解析xml,然後將其顯示在頁面上(將它附加到#container)。在附加的html中,添加li。在此之後,我需要迭代到正確的目標li。因此,如果我點擊xml id爲3的目標li,我需要爲所有迭代的xml節點僅爲目標li啓動一個函數。任何直接的一如既往是非常感謝。
謝謝!
的jQuery:
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="js/video-js/video.js"></script>
<link rel="stylesheet" href="js/video-js/video-js.css" type="text/css" media="screen" title="Video JS" charset="utf-8">
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "videos.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('videos').each(function(){
var title = $(this).find('title').text();
var id = $(this).find('id').text();
var url = $(this).find('url').text();
var url2 = $(this).find('url2').text();
var desc = $(this).find('desc').text();
//alert(url2);
$('#container').append('<div id="desc">'+title+'<br>'+desc+'</div><video class="video-js" width="740" height="400" controls="controls" preload="true"><source src="'+url+'"/><source src="'+url2+'"/></video><li class="video-thumb">'+id+'</li>');
$('.video-thumb').click(function() {
if(id == 2){
alert("click = " + id);
} else {
return false
alert("loser");
}
})
});
}
});
//VideoJS.setupAllWhenReady();
});
XML:
<xml>
<videos>
<title>title one</title>
<id>1</id>
<url>videos/video1.mp4</url>
<url2>videos/video1.webm</url2>
<desc>111 Writing things in here. Writing things in here. Writing things in here.</desc>
</videos>
<videos>
<title>title 2</title>
<id>2</id>
<url>videos/video1.mp4</url>
<url2>videos/video1.webm</url2>
<desc>2 Writing things in here. Writing things in here. Writing things in here.</desc>
</videos>
<videos>
<title>title 3</title>
<id>3</id>
<url>videos/video1.mp4</url>
<url2>videos/video1.webm</url2>
<desc>3 Writing things in here. Writing things in here. Writing things in here.</desc>
</videos>
<videos>
<title>title 4</title>
<id>4</id>
<url>videos/video1.mp4</url>
<url2>videos/video1.webm</url2>
<desc>4 Writing things in here. Writing things in here. Writing things in here.</desc>
</videos>
</xml>
請解決您的格式。 –