我有這樣的HTML:的getElementById在有序列表
<ul class="ei-slider-arrows">
<li id="arrowLeft" ><img src='images/close.png'/></li>
<li id="arrowRight" ><img src='images/close.png'/></li>
</ul>
我想對我的兩個立「箭頭」添加點擊功能,但我不能選擇它們。我嘗試這樣做:
this.$arrows = this.$el.find('ul.ei-slider-arrows');
this.$arrowLR = this.$arrows.children('li');
this.$arrowRight = this.$arrowLR.getElementById("arrowRight");
我可以this.$arrowLR
增加一個功能,但我不能設法選擇arrowRight
。 在這裏我嘗試了getElementById
,但我也嘗試過get(0)
和get(1)
。
任何人都有一個想法,爲什麼它不工作?
如果我做console.log(this.$arrowRight)
它只在控制檯中顯示[]
(get()
和getElementById("arrowRight")
)。
請張貼更多的HTML和JS - 這很難從你發佈給我們幫助的一點點。 – Utkanos 2012-07-30 16:33:20
所以我用這個工作完美'這個。$ arrowRight = this. $ arrows.find('li.arrowRight img');' – 2012-07-30 17:20:09