目录

one()

功能

为元素的事件添加处理函数。处理函数在每个元素上每种事件类型最多执行一次。

语法

eventer.one(elm, event, selector, data, callback)

参数

参数

范例

Example: 处理函数在每个元素上每种事件类型只执行一次。

<!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>
    <div class="count">0</div>
    <button class="target">Counter</button>
    <script>
    require(["skylark/query", "skylark/eventer"], function($, eventer) {
        var count = $(".count"),
            value = count.text();
        eventer.one($(".target")[0], "click mouseenter", function() {
            count.html(++value);
        });
    });
    </script>
</body>

</html>