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];
}
}
})