【发布时间】:2015-09-09 15:20:55
【问题描述】:
我正在尝试根据我使用eq() 获得的元素触发点击事件。
我有三个具有相同类名的元素:ag-list-item。
<!-- item one -->
<div ag-repeat="" class="ag-list-item ag-not-dragging">
<span>
<span class="ag-visible-icons">
</span>
<span>Avg. Yield (bu/ac)</span>
</span>
</div>
<!-- /item one -->
<!-- item two -->
<div ag-repeat="" class="ag-list-item ag-not-dragging">
<span>
<span class="ag-visible-icons">
</span>
<span>Total Average</span>
</span>
</div>
<!-- /item two -->
<!-- item three -->
<div ag-repeat="" class="ag-list-item ag-not-dragging">
<span>
<span class="ag-visible-icons">
</span>
<span>Crop Type</span>
</span>
</div>
<!-- /item three -->
我正在尝试在特定 ag-list-item 元素的嵌套 span 元素上触发点击事件。我使用 :first 来点击第一个,但想定位到特定的索引(即第一、第二、第三等)
// click all with .ag-list-item class
$('.ag-list-item span span').click()
// click first item in set
$('.ag-list-item:first span span').click()
// try to only click the second item in the set
// get second
var el = $('.ag-list-item').children('span span').eq(2);
// click second item in set
$(el).click();
请帮忙!
【问题讨论】:
-
您的问题在这里不清楚。代码
$(el).click();不适合您吗?您能否在jsFiddle 上发布一个说明您的问题的功能示例。 -
你想
$('.ag-list-item').eq(2).children('span span')吗? -
FWIW;
.eq()构造了一个新的jQuery对象,所以不用包装el,它已经是一个jQuery对象了。
标签: javascript jquery html javascript-events