我有以下代码,直接来自教程:
<!DOCTYPE HTML>
<head>
<link rel="stylesheet" href="js/dijit/themes/claro/claro.css" />
<script src="js/dojo/dojo.js" data-dojo-config="async: 1, parseOnLoad: 1"></script>
<script>
require(["dojo/_base/fx", "dojo/on", "dojo/dom", "dojo/parser", "dojo/domReady!"], function(fx, on, dom, parser)
{
var fadeOutButton = dom.byId("fadeOutButton"),
fadeInButton = dom.byId("fadeInButton"),
fadeTarget = dom.byId("fadeTarget");
on(fadeOutButton, "click", function(evt)
{
fx.fadeOut({ node: fadeTarget }).play();
});
on(fadeInButton, "click", function(evt)
{
fx.fadeIn({ node: fadeTarget }).play();
});
});
</script>
</head>
<body class="claro">
<button data-dojo-type="dijit/form/Button" type="button" id="fadeOutButton">Fade block out</button>
<button data-dojo-type="dijit/form/Button" type="button" id="fadeInButton">Fade block in</button>
<div id="fadeTarget" style="background: red; height: 256px">
A red block
</div>
</body>
</html>
我的目标是让按钮设置Dojo样式。据我所见,这是由解析器完成的。这个问题是解析器将更改按钮元素的id,因此不会触发事件。如果我从dojo/parser
删除require
或将parseOnLoad
更改为0,则按钮可以正常工作,但它们不是样式。使用上面的代码,按钮的样式但不起作用。是否有可能同时拥有?
答案 0 :(得分:0)
我想我弄清楚了 - 我必须使用registry.byId
代替dom.byId