单击以在 2 个函数之间切换 jquery

Click to change between 2 function jquery

toggle() 方法在 jQuery 1.8 版中已弃用,并在 1.9 版中删除。 Documentation

如何在 jQuery 1.11+ 中使用类似 toggle() 的功能?

Fiddle

中的完整代码
<script>
    function test(){
        $("*:contains(ไทย):last").text("English");
    }
    function test2(){
        $("*:contains(English):last").text("ไทย");
    }

    $("#click").toggle(
        test(),
        test2();
    });
</script>

我不知道这种行为,但有我的解决方案:

function test(){
    $("*:contains(ไทย):last").text("English");
}
function test2(){
    $("*:contains(English):last").text("ไทย");
}

var el = document.getElementById("click");
$(el).click(function (e) {
    el.foo.apply(this, arguments);
});

el.foo = test;
el.toggle = function () {
    el.foo = el.foo === test ? test2 : test;
};