我使用我的網頁jQuery的手風琴,這裏是HTML,追加<a>使用jQuery
<div class="forms-cont">
<h5>
Accordian Examples</h5>
<div class="accordian">
<div>
<h2 class="sch-hdr">
Header One</h2>
<div class="sch-cont levelOne">
<p>
this is a title text - level one</p>
</div>
</div>
<div class="">
<h2 class="sch-hdr">
Header Two</h2>
<div class="sch-cont levelOne">
<p>
This is another title text - level one
</p>
<div class="martop10">
<h3 class="subgr-hdr">
Staff</h3>
<div class="sch-cont levelTwo">
<p>
This is an inner text
</p>
</div>
</div>
<div class="">
<h3 class="subgr-hdr">
Manager</h3>
<div class="sch-cont levelTwo">
<p>
This is an inner text
</p>
</div>
</div>
</div>
</div>
</div>
</div>
在此,我需要附加的手風琴工作錨標記,這裏是我的jQuery,
$(document).ready(function() {
// Accordian Main
$('.accordion h2, .accordion h3').addClass('closed');
$('.levelOne,.levelTwo').hide();
$('.accordion h2, .accordion h3').each(function() {
$(this).html(function() {
var headertext = '<a href="#">' + $(this).html() + '</a>';
return headertext;
});
});
// Level 1 Accordian
$(".accordion h2 a").click(function() {
alert('hi');
$(this).next(".levelOne").slideToggle("slow");
$(this).toggleClass("closed");
return false;
});
// Level 2 Accordian
$('.accordion h3 a').click(function() {
$(this).parent().next(".levelTwo").slideToggle("slow");
$(this).parent().toggleClass("closed");
return false;
});
});
但我無法在H2和H3中附加錨。任何幫助?
一個錯字'accordian'在HTML和'accordion'在你的js – 2012-08-01 09:18:27
你實際上並沒有與此代碼創建一個手風琴... – 2012-08-01 09:18:28
小提琴將幫助 – techfoobar 2012-08-01 09:19:28