Dojo显示/隐藏包含programmaticaly生成的组合框的DIV

时间:2016-05-03 18:08:02

标签: dojo

我是Dojo的新手。这是我的问题。请求帮助。

选择状态单选按钮时,应显示状态组合框。选择“区域”单选按钮时,应显示“区域”组合框。但我的代码似乎不起作用。

小提琴项目是here



require([
  'dojo/dom',
  'dojo/dom-construct',
  'dojo/dom-style',
  'dojo/query',
  'dojo/on',
  'dojo/store/Memory', 
  'dijit/form/ComboBox',
  'dojo/domReady!'
], function (dom, domConstruct,domStyle,query,on, Memory, ComboBox) {
var stateStore = new Memory({
        data: [
            {name:"Alabama", id:"AL"},
            {name:"Alaska", id:"AK"},
            {name:"American Samoa", id:"AS"},
            {name:"Arizona", id:"AZ"},
            {name:"Arkansas", id:"AR"},
            {name:"Armed Forces Europe", id:"AE"}
        ]
    });

    var regionStore = new Memory({
        data: [
            {name:"North Central", id:"NC"},
            {name:"South West", id:"SW"}
        ]
    });
    
    var comboState = new ComboBox({
        id: "stateSelect",
        name: "state",
        store: stateStore,
        searchAttr: "name"
    }, "state").startup();
    
     var comboRegion = new ComboBox({
        id: "regionSelect",
        name: "region",
        store: regionStore,
        searchAttr: "name"
    }, "region").startup();
    
   domStyle.set(dom.byId('state'), "display", "block");
   domStyle.set(dom.byId('region'), "display", "none");

   on(query('.radio'),'change',function(){
    query('.query').forEach(function(divElement){
        domStyle.set(divElement, "display", "none");
    });
    domStyle.set(dom.byId(this.dataset.target), "display", "block");
   });
});

.hidden {
  display: none;
}

<input class="radio" data-target="state" type="radio" name="selection" value="state">State
<input class="radio" data-target="region" type="radio" name="selection" value="region">Region

<div id="state" class="query hidden"></div>
<div id="region" class="query hidden"></div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

查询然后连接lke:

更直接
query('.radio').on('change', function(){
alert("bing")
})