嗨请帮助我获取输出...我试图在div元素中显示CheckedMultiSelect中的所选项目。请帮助我找出错误
<html>
<link rel="stylesheet" href="dijit/themes/claro/claro.css">
<style type="text/css">
@import "dojox/form/resources/CheckedMultiSelect.css";
</style>
<script>dojoConfig = {parseOnLoad: true}</script>
<script src="dojo/dojo.js"></script>
<script>
require(["dojox/form/CheckedMultiSelect"]);
require(["dijit/registry"], function(registry){
var a=registry.byId("multiselect");
dom.byId("textNode2").innerHTML="Found my text box. It has value: [" + a.get('value') + "] and its primary DOM node tag name is: [" + dNode.tagName + "]";
});
</script>
<body class="claro">
<select multiple="true" data-dojo-type="dojox.form.CheckedMultiSelect" id="multiselect" name="multiselect" >
<option value="TN">Tennessee</option>
<option value="VA" selected="selected">Virginia</option>
<option value="WA">Washington</option>
<option value="FL">Florida</option>
<option value="CA">California</option>
</select>
<div id="textNode2" style="background-color: lightgray"></div>
</body>
</html>
答案 0 :(得分:0)
您提供的代码中的问题是在语句中显示:
dom.byId("textNode2").innerHTML="Found my text box. It has value: [" + a.get('value') + "] and its primary DOM node tag name is: [" + dNode.tagName + "]";
});
您正在引用一个名为dom
的变量,该变量未定义。另外,您指的是一个名为dNode
的变量,它未被声明。
由于脚本在head部分中运行,因此在执行脚本时DOM也可能没有准备就绪。
我编写了以下内容并且有效:
<script>
require(["dijit/registry", "dojo/dom", "dojo/parser", "dojox/form/CheckedMultiSelect", "dojo/domReady!"], function(registry, dom, parser){
parser.parse();
var a=registry.byId("multiselect");
dom.byId("textNode2").innerHTML="Found my text box. It has value: [" + a.get('value') + "]";
});
</script>