我使用的是 jQuery 1.11.0,只要我加载 jquery-migrate,这个简短的切换代码就可以正常工作。当我不加载 jquery-migrate 文件时,我没有看到任何 js 错误,但页面上没有显示任何文本。是什么破坏了它?
jQuery(function ($) {
$(".toggle_content").hide();
$("h4.toggle").toggle(function () {
$(this).addClass("clicked");
}, function () {
$(this).removeClass("clicked");
});
$("h4.toggle").click(function () {
$(this).find(".toggle_icon").toggleClass("fa-rotate-270 norotate");
$(this).next(".toggle_content").slideToggle();
});
});
最佳答案
此处已弃用的函数是 toggle()
。它仍然存在,但它不再接受在您的代码尝试时交替执行两个函数。对于您的情况,您可以将其替换为 toggleClass
:
jQuery(function($){
$(".toggle_content").hide();
$("h4.toggle").click(function(){
$(this)
.toggleClass("clicked")
.find(".toggle_icon").toggleClass("fa-rotate-270 norotate").end()
.next(".toggle_content").slideToggle();
});
});
关于jquery - 这里哪个函数已被弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24998541/