-1

嗨,请帮助我获取输出...我正在尝试在 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>
4

1 回答 1

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>
于 2013-11-04T22:43:56.200 回答