问题
I want to open a slider on the next page when pressing a button but there is more than one button. Further, when I press one of the buttons then I want the info slider to open the one I clicked on the previous page.
here is the code:
$(document).ready(function () {
$("h3.open-close").click(function () {
if ($(this).is(".current")) {
$(this).removeClass("current");
$(this).next(".desc").slideUp(400);
} else {
$(".desc").slideUp(4.00);
$("h3.open-close").removeClass("current");
$(this).addClass("current");
$(this).next(".desc").slideDown(400);
$(function () {
if (window.location.hash) {
$(window.location.hash).show();
}
});
}
});
});
回答1:
Your updated code:
$(document).ready(function () {
if (window.location.hash) {
$(window.location.hash).show(); // <--if true then do this.
}
$("h3.open-close").click(function () {
if ($(this).is(".current")) {
$(this).removeClass("current");
$(this).next(".desc").slideUp(400);
} else {
$(".desc").slideUp(4.00);
$("h3.open-close").removeClass("current");
$(this).addClass("current");
$(this).next(".desc").slideDown(400);
}
});
});
You have to check for the hash at dom ready.
来源:https://stackoverflow.com/questions/22346848/how-to-open-a-specific-slider-on-the-next-page-with-jquery