【问题标题】:Click to change between 2 function jquery单击以在 2 个函数 jquery 之间切换
【发布时间】:2016-06-10 15:09:41
【问题描述】:

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>

【问题讨论】:

标签: javascript jquery function toggle


【解决方案1】:

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

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;
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 2021-01-25
    相关资源
    最近更新 更多