目录

trigger()

功能

根据绑定到匹配元素的给定的事件类型执行所有的处理程序和行为。

语法

eventer.trigger(evented, type, args)

参数

范例

Example: 点击 button #2 时,同时触发 button #1 的点击事件。

<!DOCTYPE html>
<html>

<head>
    <style>
    button { margin: 10px;}
    div { color: blue;font-weight: bold;}
    span { color: red;}
    </style>
    <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>Button #1</button>
    <button>Button #2</button>
    <div><span>0</span> button #1 clicks.</div>
    <div><span>0</span> button #2 clicks.</div>
    <script>
    require(["skylark/query", "skylark/finder", "skylark/eventer"], function(query, finder, eventer) {
        query("button:first").click(function() {
            update(query("span:first"));
        });
        query("button:last").click(function() {
            eventer.trigger(query("button:first"), "click");

            update(query("span:last"));
        });

        function update(j) {
            var n = parseInt(j.text(), 10);
            j.text(n + 1);
        }

    });
    </script>
</body>

</html>