我遇到dojo按钮问题。 我想点击按钮时禁用其他dojo按钮。
var show = new Button({
label: _('Button'),
onClick: function () {
var buttonsChange = query('.changeButton');
buttonsChange.attr('disabled',true);
}
});
和生成的HTML代码是这样的:
<span class="btn" dojoattachpoint="iconNode" dojoattachevent="ondijitclick:_onClick" widgetid="change_2">
<button type="submit" dojoattachpoint="focusNode" tabindex="0" id="change_2" class="changeButton" style="-webkit-user-select: none;">
<span dojoattachpoint="containerNode">Change priority</span>
</button>
</span>
提前致谢。
答案 0 :(得分:0)
你需要的是小部件(例如使用dijit/registry
)。而不是domnode
require(['dijit/form/Button', 'dijit/registry', 'dojo/query', 'dojo/domReady!'], function(Button, registry, query) {
var testDiv = document.getElementById('test');
var btn1 = new Button({
label: 'click to disable button 2 and button 3',
onClick: function () {
var buttonsChange = query('.changeButton');
buttonsChange.forEach(function(button) {
registry.byNode(button).set('disabled', true);
});
}
}).placeAt(testDiv);
var btn2 = new Button({
label: 'button 2',
'class': 'changeButton'
}).placeAt(testDiv);
var btn3 = new Button({
label: 'button 3',
'class': 'changeButton'
}).placeAt(testDiv);
});
&#13;
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/resources/dojo.css">
<link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/tundra/tundra.css">
<div class="tundra" id="test"></div>
&#13;