私は、誰かがjQueryのアコーディオンonclickにコンテンツをロードすることに関する問題を解決するのを手伝ってくれることを願っています。現在、アコーディオン機能が動作していてAJAXによってコンテンツがロードされていますが、ページが読み込まれたときにすべてのコンテンツをロードするのではなく、特定のアコーディオンリーフをユーザーがクリックしたときにのみコンテンツをロードします。ページのコンテンツを読み込むOnclick - AJAX
HTML:
<div class="accordionButton">Origin</div>
<div class="accordionContent">
<a href="javascript:void(0)" class="close">Close</a>
<div id="success_origin"></div>
<div id="error_origin"></div>
<script>
$("#success_origin").load("content_origin.html", function(response, status, xhr) {
if (status == "error_origin") {
var msg = "Sorry but there was an error when loading the page's content: ";
$("#error_origin").html(msg + xhr.status + " " + xhr.statusText);
}
});
</script>
</div>
<div class="accordionButton">Style</div>
<div class="accordionContent">
<a href="javascript:void(0)" class="close">Close</a>
<div id="success_style"></div>
<div id="error_style"></div>
<script>
$("#success_style").load("content_style.html", function(response, status, xhr) {
if (status == "error_style") {
var msg = "Sorry but there was an error when loading the page's content: ";
$("#error_style").html(msg + xhr.status + " " + xhr.statusText);
}
});
</script>
</div>
のように...
アコーディオンのJavaScript:
$(document).ready(function() {
$('.close').click(function() {
$('.close').addClass('hide');
$('.accordionContent').slideUp('normal');
$('.accordionButton').addClass('on');
$('.accordionButton').removeClass('off');
$('.showHeadline').slideDown('normal');
});
$('.accordionButton').click(function() {
$('.accordionButton').removeClass('on');
$('.accordionButton').addClass('off');
$('.showHeadline').slideUp('normal');
$('.accordionContent').slideUp('normal');
//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
if($(this).next().is(':hidden') == true) {
$('.close').addClass('show');
$(this).addClass('on');
$(this).next().slideDown('normal');
}
});
$('.accordionButton').mouseover(function() {
$(this).addClass('over');
}).mouseout(function() {
$(this).removeClass('over');
});
$('.accordionContent').hide();
});
私はそれは単純なものだと確信していますが、私は非常に任意の助けをいただければと思います。
おかげで、 @rrfive