目录

matches()

功能

在选择器上检查指定的元素。

语法

finder.matches(elm, selector)

参数

范例

Example: 匹配测试 class 名是否为 “test”,如果是alert “matched”,否则alert “matched”。

<!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="test">this is a test dom whose class name is test! </div>
    <button>div.test</button>
    <button>div.test1</button>
    <script>
    require(["skylark/query", "skylark/finder"], function($, finder) {
        var div = finder.find("div");
        $("button").on("click", function() {
            var value = finder.matches(div, $(this).text());
            alert(value ? "matched" : "not matched");
        });
    });
    </script>
</body>

</html>