2013-03-05 72 views
0

以下是Html结构。现在我想要使用Jquery获得Div ID Inner_1_0,Inner_1_1,Inner_1_2,Inner_1_3等点击nextButtonprevButton。所以我应该如何检索。如何使用jquery获取ID?

更多,我给演示链接。请参阅演示

<div id="Inner_1_0" class="slideItem" style="width: 600px; height: 440px; top: 0px; right: 165px; opacity: 1; z-index: 17; display: block;"> 
    <a href="#" onclick="loadVideo(&quot;x_elT6zkqN0&quot;);" title="" oh="" jane="" jaana"="" salman="" khan="" full="" song="" |="" pyaar="" kiya="" toh="" darna="" kya"=""><img src="http://img.youtube.com/vi/x_elT6zkqN0/hqdefault.jpg" width="213px" height="141px" style="width: 600px; height: 400px;"></a> 
    <div class="shadow" style="width: 600px; z-index: -1; position: absolute; margin: 0px; padding: 0px; border: none; overflow: hidden; left: 0px; bottom: 0px;"> 
     <div class="shadowLeft" style="position: relative; float: left;"></div> 
     <div class="shadowMiddle" style="position: relative; float: left; width: 400px;"></div> 
     <div class="shadowRight" style="position: relative; float: left;"></div> 
    </div> 
</div> 
<div id="Inner_1_1" class="slideItem" style="width: 600px; height: 440px; top: 0px; right: 165px; opacity: 1; z-index: 17; display: block;"> 
    <a href="#" onclick="loadVideo(&quot;x_elT6zkqN0&quot;);" title="" oh="" jane="" jaana"="" salman="" khan="" full="" song="" |="" pyaar="" kiya="" toh="" darna="" kya"=""><img src="http://img.youtube.com/vi/x_elT6zkqN0/hqdefault.jpg" width="213px" height="141px" style="width: 600px; height: 400px;"></a> 
    <div class="shadow" style="width: 600px; z-index: -1; position: absolute; margin: 0px; padding: 0px; border: none; overflow: hidden; left: 0px; bottom: 0px;"> 
     <div class="shadowLeft" style="position: relative; float: left;"></div> 
     <div class="shadowMiddle" style="position: relative; float: left; width: 400px;"></div> 
     <div class="shadowRight" style="position: relative; float: left;"></div> 
    </div> 
</div> 
<div id="Inner_1_2" class="slideItem" style="width: 600px; height: 440px; top: 0px; right: 165px; opacity: 1; z-index: 17; display: block;"> 
    <a href="#" onclick="loadVideo(&quot;x_elT6zkqN0&quot;);" title="" oh="" jane="" jaana"="" salman="" khan="" full="" song="" |="" pyaar="" kiya="" toh="" darna="" kya"=""><img src="http://img.youtube.com/vi/x_elT6zkqN0/hqdefault.jpg" width="213px" height="141px" style="width: 600px; height: 400px;"></a> 
    <div class="shadow" style="width: 600px; z-index: -1; position: absolute; margin: 0px; padding: 0px; border: none; overflow: hidden; left: 0px; bottom: 0px;"> 
     <div class="shadowLeft" style="position: relative; float: left;"></div> 
     <div class="shadowMiddle" style="position: relative; float: left; width: 400px;"></div> 
     <div class="shadowRight" style="position: relative; float: left;"></div> 
    </div> 
</div> 
<div id="Inner_1_3" class="slideItem" style="width: 600px; height: 440px; top: 0px; right: 165px; opacity: 1; z-index: 17; display: block;"> 
    <a href="#" onclick="loadVideo(&quot;x_elT6zkqN0&quot;);" title="" oh="" jane="" jaana"="" salman="" khan="" full="" song="" |="" pyaar="" kiya="" toh="" darna="" kya"=""><img src="http://img.youtube.com/vi/x_elT6zkqN0/hqdefault.jpg" width="213px" height="141px" style="width: 600px; height: 400px;"></a> 
    <div class="shadow" style="width: 600px; z-index: -1; position: absolute; margin: 0px; padding: 0px; border: none; overflow: hidden; left: 0px; bottom: 0px;"> 
     <div class="shadowLeft" style="position: relative; float: left;"></div> 
     <div class="shadowMiddle" style="position: relative; float: left; width: 400px;"></div> 
     <div class="shadowRight" style="position: relative; float: left;"></div> 
    </div> 
</div> 

<div class="nextButton"></div> 
<div class="prevButton"></div> 

Demo link.

+0

你想在一行中用逗号分隔吗? – Silagy 2013-03-05 06:48:28

+0

不,当我点击第一次“nextButton”时,我会得到“Inner_1_1”,当我点击第二次,然后我会得到“Inner_1_2”。 – 2013-03-05 06:53:26

+0

你想要做什么?你想做一个滑块吗?或向导? – IamStalker 2013-03-05 06:56:24

回答

1

的样子,你应该使用转盘的回调函数(/前后)这一点。

before: function (carousel) { alert(carousel.current)}, 

检查下面的jsfiddle。

http://jsfiddle.net/4HSpH/10/

+0

这正是我想要的...谢谢:) – 2013-03-05 08:11:40

0

这将设置一个计数器和警报时,按下按钮,滑块的ID:

var current_slide = 0; 
$(".nextButton").click(function() { 
    alert($(".slideItem")[current_slide].id; 
    current_slide++; 
} 
0

以及你可以使用

var ids = $("#container").children().map(function(n, i) { 
    return n.id; 
}); 

或每():

var ids = $("#container").children().each(function(n, i) { 
    var id = this.id; 
    //your code 
}); 

这里的容器是承载所有这些div

1

如果你能得到当前选择的项目,然后我们可以通过下面的代码

获得next和prev项目DIV
//For Next 
      var nextdivId = $(selectedItem).next().attr("id"); 
//For Prev 
      var prevdivId = $(selectedItem).prev().attr("id"); 

让我知道你是否有任何问题。

1

你可以使用你的转盘after功能,如:

$('.carousel').carousel({ 
    carouselWidth: 930, 
    carouselHeight: 330, 
    directionNav: true, 
    shadow: true, 
    buttonNav: 'bullets', 
    after: function(obj) { 
     alert($("div.slideItem").eq(obj.current).attr("id")); 
    } 
}); 

更新小提琴demo

+0

我的问题已解决:) – 2013-03-05 08:25:55

+0

很高兴它为你工作... :) – 2013-03-05 08:47:08