jquery - 这里哪个函数已被弃用?

标签 jquery

我使用的是 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/

相关文章:

jquery - jquery mobile 和 Phonegap 的大型数据库

javascript - 鼠标&触摸水平div滑动

javascript - Bootstrap 4 轮播控件不工作

javascript - CSS AngularJS 使 div 在具有起始静态宽度时动态增长

javascript - 非法字符。在第 '4' 行位置 '6' JavaScript 错误

javascript - 第一次运行后水平菜单不会隐藏

jquery - 基于元素可见性的功能不起作用?

javascript - 如何在离开当前页面之前加载链接页面

javascript - 显示/隐藏从函数中提取的标记

javascript - 如何保护我的 php、jquery、ajax 请求免受黑客攻击?