dojo按钮未被禁用

时间:2015-08-14 10:07:07

标签: button dojo disabled-input

我遇到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>

提前致谢。

1 个答案:

答案 0 :(得分:0)

你需要的是小部件(例如使用dijit/registry)。而不是domnode

&#13;
&#13;
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;
&#13;
&#13;