這裏是我的問題:jQuery選擇憑身份證不能正常工作
我有一組由一個jQuery腳本管理3個手風琴框,如下圖所示:
jQuery(document).ready(function($) {
jQuery('.accordion .accordion-section-content').hide();
jQuery('.accordion .accordion-section-title:first').addClass('active').next().show();
jQuery('.accordion .accordion-section-title').click(function(){
if(jQuery(this).next().is(':hidden')) {
jQuery('.accordion .accordion-section-title').removeClass('active').next().slideUp();
jQuery(this).toggleClass('active').next().slideDown();
}else {
\t jQuery(this).removeClass('active').next().slideUp();
}
return false; // Prevent the browser jump to the link anchor
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="accordion">
\t \t \t <div class="accordion-section">
\t \t \t \t <a class="accordion-section-title" style="text-align: center;" href="">Title1</a>
\t \t \t \t <div id="accordion-1" class="accordion-section-content">
\t \t \t \t \t <p>Some text</p>
\t \t \t \t </div><!--end .accordion-section-content-->
\t \t \t </div><!--end .accordion-section-->
\t \t \t <div class="accordion-section">
\t \t \t \t <a class="accordion-section-title" style="text-align: center;" href="">Title2</a>
\t \t \t \t <div id="accordion-2" class="accordion-section-content">
\t \t \t \t \t <p>Some text.</p>
\t \t \t \t </div><!--end .accordion-section-content-->
\t \t \t </div><!--end .accordion-section-->
\t \t \t <div class="accordion-section">
\t \t \t \t <a class="accordion-section-title" style="text-align: center;" href="">Title3</a>
\t \t \t \t <div id="accordion-3" class="accordion-section-content">
\t \t \t \t \t <p>Some text.</p>
\t \t \t \t </div><!--end .accordion-section-content-->
\t \t \t </div><!--end .accordion-section-->
\t \t </div><!--end .accordion-->
正如你可以看到第二個jQuery將第一個手風琴盒初始化爲在頁面加載時可見,這很好。但我希望能夠顯示第二個,即中間的一個。因此,我試圖通過
jQuery('#accordion-2')
jQuery('.accordion #accordion-2')
jQuery('.accordion').find('#accordion-2')
jQuery('.accordion .accordion-section-title #accordion-2')
和其他各種可能性,我能找到選擇由ID(我相信在這種情況下,合適嗎?)的元素來改變
jQuery('.accordion .accordion-section-title:first')
,沒有什麼不...
我不明白爲什麼。
媽,我累了...謝謝你這麼多,不能相信我沒看出來! :-) –