当前位置 : 主页 > 网页制作 > Dojo >

Dojo 调用 js中的方法

来源:互联网 收集:自由互联 发布时间:2021-06-15
HTML代码: !DOCTYPE htmlhtmlheadmeta http-equiv="Content-Type" content="text/html; charset=utf-8"/ title/titlemeta charset="utf-8" / script src="../js/jquery.min.js"/script script src="../js/jquery.js"/script script src="../js/dojo.js"/s
HTML代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
	<meta charset="utf-8" /> 
    <script src="../js/jquery.min.js"></script>
    <script src="../js/jquery.js"></script>
    <script src="../js/dojo.js"></script>
</head>
<body>
    <button type="button" id="btn">按钮</button>
    <script>
        var dojoConfig = {
            async: true,
            //此代码寄存器的“演示”包正确的位置,所以我们可以从CDN加载Dojo的同时还能够加载本地模块
            packages: [{
                name: "DojoTest",
                location: location.pathname.replace(/\/[^/]*$/, '') + '/DojoTest'
            }]
        };

        require(['DojoTest/forDojoTest'], function (dj) {
            dj.setText("btn", "NEW BUTTON");
            setTimeout(function () { dj.responseText("btn") }, 3000);
        });


    </script>
</body>
</html>
 

JS代码

define(['dojo/dom'], function (dom) {
    var oldText = {};
    return {
        setText: function (id, text) {
            var node = dom.byId(id);
            oldText[id] = node.innerHTML;
            node.innerHTML = text;
        },

        responseText: function (id) {
            var node = dom.byId(id);
            node.innerHTML = oldText[id];
            delete oldText[id];
        }
    }
})
 
网友评论