使用Dojo设置以编程方式生成的组合框的样式

时间:2016-05-05 17:17:57

标签: dojo

我想使用下面的dojo代码设置以编程方式生成的组合框的文本大小。宽度和高度有效但不是字体大小。



var cboState = new ComboBox({
                             id: "usastate",
                             name: "usastate",
                             style:{width: "100%", height: "40px", fontsize: "20px"},
                             placeholder: "Select a State",
                             store: stateStore,
                             searchAttr: "name",
                             autocomplete: true
});




2 个答案:

答案 0 :(得分:2)

fontsize更改为fontSize,它会有效。

var cboState = new ComboBox({
                          id: "usastate",
                          name: "usastate",
                          style:{width: "100%", height: "40px", fontSize: "20px"},
                          placeholder: "Select a State",
                          store: stateStore,
                          searchAttr: "name",
                          autocomplete: true
});

或者,您也可以将style作为字符串传递:

var cboState = new ComboBox({
                          id: "usastate",
                          name: "usastate",
                          style:"width: '100%'; height: '40px'; font-size: '20px'",
                          placeholder: "Select a State",
                          store: stateStore,
                          searchAttr: "name",
                          autocomplete: true
});

答案 1 :(得分:1)

好吧,我已经添加了运行样本。以及添加的自定义样式。

require([
    "dojo/store/Memory", "dijit/form/ComboBox", "dojo/domReady!"
], function(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"},
            {name:"Armed Forces Pacific", id:"AP"},
            {name:"Armed Forces the Americas", id:"AA"},
            {name:"California", id:"CA"},
            {name:"Colorado", id:"CO"},
            {name:"Connecticut", id:"CT"},
            {name:"Delaware", id:"DE"}
        ]
    });
  
    var comboBox = new ComboBox({
      id: "usastate",
      name: "usastate",
      style:{width: "200px", height: "28px", fontSize: "20px"},
      placeholder: "Select a State",
      store: stateStore,
      searchAttr: "name",
      autocomplete: true
    }, "stateSelect").startup();
});
<script data-dojo-config="async: 1"
            src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
 <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/claro/claro.css" media="screen">
<body class="claro">
    <input id="stateSelect">
</body>

希望这会对您有所帮助:)