<script>
require(["dojo/dom", "dojo/dom-construct", "dojo/on", "dojo/domReady!"], function(dom, domConstruct, on) {
domConstruct.empty(dom.byId("buttonNode"));
});
var count=1;
function change() {
if(count == 1) {
require(["dojo/ready", "dijit/form/Button", "dojo/dom"], function(ready, Button, dom){
ready(function(){
var myButton = new Button({
label: "Count 1",
onClick: function(){
count++;
change();
}
}, "buttonNode");
});
});
} else if(count ==2) {
require(["dojo/ready", "dijit/form/Button", "dojo/dom"], function(ready, Button, dom){
ready(function(){
var myButton = new Button({
label: "Count 2",
onClick: function(){
count++;
change();
}
}, "buttonNode");
});
});
}
}
</script>
</head>
<body class="claro" onload="change()">
<button id="buttonNode" type="button" onclick="change()"></button>
</body>
</html>
单击按钮时,它的显示尝试使用 id==buttonNode 注册小部件,但该 id 已注册,但我在使用 domConstruct.empty 创建新按钮之前删除旧按钮。我尝试了 domConstruct.empty("buttonNode"); domConstruct.empty(dom.byId("buttonNode"));
我想要为不同的登录用户提供不同的按钮,例如发送请求、取消请求等,所以我正在检查条件并创建新按钮。问题是如果按钮已经用那个 ID 创建了我无法替换按钮请帮助我。