我有手风琴和音响。我想控制下一个/上一个。得到工作。现在单击$(this)
选项卡切换但另一个没有打开,下一首曲目没有播放。(按下下一个/上一个控制按钮时想要打开下一个手风琴并播放曲目。
这是我的手风琴JS代码:
var next = jQuery('.my_music').find('.accordion-toggle');
next.click(function(){
jQuery(this).next().slideToggle('fast');
jQuery(".accordion-content").not(jQuery(this).next()).slideUp('fast');
});
切换下一首曲目:
jQuery('.next_music').click(function(){
// jQuery(next).next().slideToggle('fast');
// cl(this);
jQuery(".accordion-content").not(jQuery(this).next()).slideUp('fast');
});
答案 0 :(得分:1)
修改强>
(删除了我的第一个答案......测试了这个。工作!;))
$(".next_music").click(function(){
var actualAccordion = $(this).parent().parent().parent('.accordion-content');
console.log("next clicked");
// find the accordion below by getting it's parent's next element (".my_music_wrap").
belowAccordion = actualAccordion.parent().next().children('.accordion-toggle').first();
// Toggle it!
if(belowAccordion.length>0){ // If an accordion is found
actualAccordion.first().slideToggle('fast'); // Toggles actual accordion.
belowAccordion.click() //.slideToggle('fast');
belowAccordion.next().first().children().children().children().children(".audioplayer-playpause").click();
}else{
alert('No other song to play!'); //Will happen on the next button of the fifth song.
}
});
$(".prev_music").click(function(){
var actualAccordion = $(this).parent().parent().parent('.accordion-content');
console.log("prev clicked");
// find the accordion below by getting it's parent's next element (".my_music_wrap").
aboveAccordion = actualAccordion.parent().prev().children('.accordion-toggle').first();
// Toggle it!
if(aboveAccordion.length>0){ // If an accordion is found
actualAccordion.first().slideToggle('fast'); // Toggles actual accordion.
aboveAccordion.click() //.slideToggle('fast');
aboveAccordion.next().first().children().children().children().children(".audioplayer-playpause").click();
}else{
alert('No other song to play!'); //Will happen on the prev button of the first song.
}
});
我重命名了您的next
var,因为这很混乱。