国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

JavaScript和Jquery:尋找被點(diǎn)擊元素的索引
P粉022140576
P粉022140576 2023-08-25 14:55:21
0
1
655
<p>我正在建立一個(gè)投影片,我在以下問題上遇到了困難 - 當(dāng)點(diǎn)擊標(biāo)籤時(shí),如何在陣列中找到位置(索引)?下面的程式碼部分取得了所有的a標(biāo)籤</p> <pre class="brush:php;toolbar:false;">this.thumbs = this.nav.find('a');</pre> <p>從那裡開始呢? 還有一個(gè)問題 - 當(dāng)點(diǎn)擊標(biāo)籤時(shí),我需要切換標(biāo)籤內(nèi)部div的類別(div標(biāo)籤需要取得class promo_tumb_current,而具有該標(biāo)籤的div需要失去它)。 </p> <p>HTML代碼:</p> <pre class="brush:php;toolbar:false;"><div class="promo_tumbs col_12"> <div data-dir="prev" class="prev"></div> <div data-dir="next" class="next"></div> <div class="promo_tumbs_centar"> <a href="#first"><div class="promo_tumb promo_tumb_current"></div></a> <a href="#second"><div class="promo_tumb"></div></a> <a href="#thrid"><div class="promo_tumb"></div></a> <a href="#fourh"><div class="promo_tumb"></div></a> <a href="#fifth"><div class="promo_tumb"></div></a> <a href="#fifth"><div class="promo_tumb"></div></a> <a href="#fifth"><div class="promo_tumb"></div></a> </div> </div></前> <p>JS代碼:</p> <pre class="brush:php;toolbar:false;"><腳本> 函數(shù)滑桿(容器,導(dǎo)航){ this.container = 容器; this.nav = 導(dǎo)航; this.li = this.container.find('li'); this.li_width = this.li.first().width(); this.li_len = this.li.length; this.thumbs = this.nav.find('a'); this.當(dāng)前 = 0; } Slider.prototype.transition = 函數(shù)(座標(biāo)){ this.container.stop().animate({ 'margin-left' : 座標(biāo) || -(this.current * this.li_width) }) } Slider.prototype.set_current = 函數(shù)(dir){ var pos = this.current; if (dir === '下一個(gè)') {pos } else if (dir === '上一個(gè)') {pos--} this.current = (pos < 0) ? this.li_len - 1 : pos % this.li_len; 返回位置; } var slider = new Slider($('div.promo_inner ul'), $('div.promo_tumbs')); slider.nav.find('div').on('點(diǎn)選', function(){ if ($(this).attr("data-dir") === 未定義 ) { var index = slider.thumbs.index(); 控制臺(tái).log(索引) } 別的 { slider.set_current($(this).data('dir')); } 滑桿.transition(); })</pre> <p></p>
P粉022140576
P粉022140576

全部回覆(1)
P粉426780515

我認(rèn)為你需要的是

http://api.jquery.com/index/

#

例如,在你的事件處理程序中(其中this是被點(diǎn)擊的a標(biāo)籤):

var index = thumbs.index($(this))
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板