이 jQuery 함수에 무엇이 잘못 되었습니까?
-
19-09-2019 - |
문제
$(function() {
$("table.section thead").click(function() {
if ($(this).next("table.section tbody").style.display == "block"){
$(this).next("table.section tbody").slideUp("slow");
}
if ($(this).next("table.section tbody").style.display == "none"){
$(this).next("table.section tbody").slideDown("slow");
}
});
});
나는 이것을 달성하는 방법을 모른다. 어떤 도움이든 대단히 감사하겠습니다.
업데이트:
다음 기능을 사용하려고했습니다.
$(function() {
$("table.section thead").click(function() {
$(this).next("table.section tbody").slideToggle("slow");
});
});
문제가 발생합니다. 그렇기 때문에 기능을 맨 위로 얻으려고합니다.
해결책
이 경우 눈에 보이는 선택기를 사용하십시오.
$(function() {
$("table.section thead").click(function() {
var body = $(this).next("table.section tbody");
if (body.is(":visible"))
body.slideUp("slow");
else
body.slideDown("slow");
});
});
그러나 아마도 훨씬 간단하게 사용됩니다 .slideToggle()
이와 같이:
$(function() {
$("table.section thead").click(function() {
$(this).next("table.section tbody").slideToggle("slow");
});
});
제휴하지 않습니다 StackOverflow