我正在使用jquery'contains'選擇器來確定單擊div時要執行的操作...我想要展開或摺疊切面導航的一部分。jquery部分展開和摺疊
但是,看起來'contains'選擇器可能只是在DOM最初加載時纔看div的內容,並且沒有看到較早的jquery調用換出的較新內容。
我有一個主要功能版本在這裏工作......只需要輕輕一推,以獲得頂部部分坍塌正確:http://jsfiddle.net/brianadkins/nAabP/
HTML:
<div class="facetname" id="facetname-fbr">
Brand
</div>
<ul class="facetvalues" id="facetvalues-fbr">
<li>facet1val1</li>
<li>facet1val2</li>
<li>facet1val3</li>
<li>facet1val4</li>
<li>facet1val5</li>
<li>facet1val6</li>
<li>facet1val7</li>
<li>facet1val8</li>
<li>facet1val9</li>
<li>facet1va10</li>
<li>facet1val11</li>
<li>facet1val12</li>
<li>facet1val13</li>
</ul>
<div class="slidermenu" id="slidermenu-fbr">
</div>
的Javascript :
var ListLengthHidingTrigger = 7;
var InitialListItems = 4;
if ($("#facetvalues-fbr li").length > ListLengthHidingTrigger) {
$("#facetvalues-fbr li:gt("+(InitialListItems-1)+")").hide(); // hide all but first N sections
$('#slidermenu-fbr').html('Show All Brands');
}
$('div#slidermenu-fbr:contains("All")').click(function() {
$('#facetvalues-fbr li').show(); // hide all but first 2 sections
$('#slidermenu-fbr').html('Show Fewer Brands');
});
$('div#slidermenu-fbr:contains("Fewer")').click(function() {
$("#facetvalues-fbr li:gt("+(InitialListItems-1)+")").hide(); // hide all but first N sections
$('#slidermenu-fbr').html('Show More Brands');
});
$('#facetname-fbr').click(function() {
$('#facetvalues-fbr').slideToggle(0);
});
它似乎是工作... – Neal 2011-03-30 19:47:13
點擊「顯示更少」 – Dutchie432 2011-03-30 19:49:21