Dojo学习笔记(四):NodeList扩展

   dojo/query返回的是匹配查询结果的所有节点构成的数组;这个数组实际上是一个特殊的数组对象称为dojo/NodeList, 该数组对象内建了一系列可以方便操作其中节点的方法。

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>NodeList</title>
    <script src="dojo/dojo.js" data-dojo-config="async: true"></script>
    <script>
        require(["dojo/query","dojo/domReady!"], function(query){
            query("li.fresh").on("click", function(){
                alert("I love fresh " + this.innerHTML);
            });
        });
    </script>
</head>
<body>
<ul>
    <li class="fresh">Apples</li>
    <li class="fresh">Persimmons</li>
    <li class="fresh">Grapes</li>
    <li class="fresh">Fresh Figs</li>
    <li class="dried">Dates</li>
    <li class="dried">Raisins</li>
    <li class="dried">Prunes</li>
    <li class="fresh dried">Apricots</li>
    <li class="fresh">Peaches</li>
    <li class="fresh">Bananas</li>
    <li class="fresh">Cherries</li>
</ul>
</body>
</html>

等效于:

<script>
        require(["dojo/query","dojo/domReady!"], function(query){
            query("li.fresh").on("click", function(e){
                alert("I love fresh " + e.target.innerHTML);
            });
        });
</script>

等效于:

  <script>
        require(["dojo/query","dojo/on","dojo/domReady!"], function(query,on){
            on(query("li.fresh"),"click", function(e){
                alert("I love fresh " + e.target.innerHTML);
            });
        });
</script>

备注:dojo/NodeList对象与DOM NodeList对象是不相同的。



























本文出自 “IT技术学习与交流” 博客,谢绝转载!

你可能感兴趣的:(query,dojo)