create()

功能

创建指定类型的事件对象。

语法

eventer.create(type,props)

参数

  • type
    事件类型、本地DOM事件类型或自定义事件类型。
  • props
    一个 name-value 对的对象来设置事件属性。

范例

Example: 点击 buttion 提示 msg: “button has been clicked”。

<!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>
    <button>click me</button>
    <p></p>
    <script>
    require(["skylark/query", "skylark/eventer"], function($, eventer) {
        var btn = $("button"),
            e = eventer.create("clicked", {
                msg: "button has been clicked"
            });

        btn.on("click", function() {
            eventer.trigger(btn, e);
        });

        btn.on("clicked", function(e) {
            $("p").html(e.msg);
        });
    });
    </script>
</body>

</html>