目录

off()

功能

从指定元素中删除一个或多个事件的事件处理程序。

语法

eventer.off(elm, events, selector, callback)

参数

范例

Example: 累计 button 点击数,最多为 5 次,则移除点击事件。

<!DOCTYPE html>
<html>

<head>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.3/require.min.js"></script>
    <script>
    require.config({
        baseUrl: "./",
        packages: [{
            name: "skylark",
            location: "../../../src/skylark"
        }, ]
    });
    </script>
</head>

<body>
    <p>clicked account: 0</p>
    <button>click me</button>
    <script>
    require(["skylark/query", "skylark/eventer"], function($, eventer) {
        var value = 0,
            btn = $("button")[0],
            clickMe = function() {
                value += 1;
                if (value > 5) return eventer.off(btn, "click", clickMe);
                $("p").html("button clicked account: " + value);
            };
        eventer.on(btn, "click", clickMe);
    });
    </script>
</body>

</html>