我无法设置道场combobox
的值,组合框是:
<select data-dojo-type="dijit.form.ComboBox" id="index" name="index" onChange="comboOnChange()">
<option value="30" >30</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
我已经尝试了所有这些选项:
dojo.widget.byId('index').setValue(index);
index.options[index.selectedIndex].text = index;
dijit.byId('index').set("value", index);
他们都没有工作,有什么建议吗?
答案 0 :(得分:0)
我不知道你是否正在使用传统的dojo模式。但是从1.6开始,dojo使用AMD样式。在您的情况下dijit.byId('index').set("value", index);
应该有效,如果有错误,请查看您的控制台!
但我强烈建议使用现代的Dojo(AMD),上面你会找到一个有效的例子(从30开始然后改为50):
require(["dojo/ready", "dojo/parser","dijit/registry","dijit/form/ComboBox","dojo/domReady!"],
function (ready, parser, Registry ,Combobox) {
parser.parse();
//be sure the widget is rendered and parsed , by calling ready
ready(function(){
//get reference to combo widget
var combo = Registry.byId("index");
// atach change event
combo.on("change",function(e){
console.log(e);
alert(this.value);
});
//here you can set value to your combo set value
combo.set("value",50);
});
});
html, body {
height: 100%;
padding: 0;
margin: 0;
font-family: Lucida Sans,Lucida Grande,Arial !important;
font-size: 13px !important;
background: white;
color: #333;
}
<link href="https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dijit/themes/claro/claro.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<script>
dojoConfig= {
parseOnLoad: false,
async: true
};
</script>
<body class="claro">
<select data-dojo-type="dijit/form/ComboBox" id="index" name="index">
<option value="30" >30</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</body>