这是我如何在我的jsp页面中声明数字旋转器元素
<table width="40%">
<tr>
<td class="proplabel"><label for="tTestDuration">Test Duration</label></td>
<td><input data-dojo-type="dijit/form/NumberSpinner" id="tTestDuration" value="60" data-dojo- props="smallDelta:1, constraints:{min:1,max:600,places:0},required:true" name="testDuration" />(Seconds)</td>
</tr>
<tr class="spacer"><td> </td></tr>
<tr>
<td class="proplabel"><label for="tTestMinFrameRate">Minimum Frame Rate</label></td>
<td><input data-dojo-type="dijit/form/NumberSpinner" id="tTestMinFrameRate" value="1" data-dojo- props="smallDelta:1, constraints:{min:1,max:10000,places:0},required:true" name="initialRate" />(Mbps)</td>
</tr>
<tr class="spacer"><td> </td></tr>
<tr>
<td class="proplabel"><label for="tTestMaxFrameRate">Maximum Frame Rate</label></td>
<td><input data-dojo-type="dijit/form/NumberSpinner" id="tTestMaxFrameRate" value="100" data-dojo- props="smallDelta:1, constraints:{min:1,max:10000,places:0},required:true" name="maximumRate"/>(Mbps)</td>
</tr>
<tr class="spacer"><td> </td></tr>
<tr>
<td class="proplabel"><label for="tTestStepSize">Step Size</label></td>
<td><input data-dojo-type="dijit/form/NumberSpinner" id="tTestStepSize" value="5" data-dojo- props="smallDelta:1, constraints:{min:1,max:100,places:0},required:true" name="stepRate" />(Mbps)</td>
</tr>
<tr class="spacer"><td> </td></tr>
<tr>
<td class="proplabel"><label for="tTestAcceptableLoss">Acceptable Loss</label></td>
<td><input data-dojo-type="dijit/form/NumberSpinner" id="tTestAcceptableLoss" value="0" data-dojo- props='smallDelta:1, constraints:{min:0,max:10,places:0},required:true' name="acceptableLoss" />(%)</td>
</tr>
</table>
在我的脚本中,我使用dojo。查询获取nodeList,然后获取节点名称和值。使用这些节点名称和值,构造一个要发送到服务器的对象。
我的问题是我无法获得节点名称,名称为空,我使用console.log()和alert()检查,但能够获得节点id和节点值
下面是我用来查询 的脚本尝试使用domAttr, dojo。attr …我什么都不管用请告诉我如何获得name属性即使是简单的**document.getElementById(node.id).name**
也不起作用
供参考:
我正在使用dojo 1.8.4版本
<script>
require([
"dojo/parser",
"dijit/form/CheckBox",
"dijit/form/NumberSpinner",
"dijit/form/Form",
"dijit/form/Button",
"dojo/dom",
"dojo/query",
"dojo/dom-attr",
"dojo/domReady!"
], function(parser,domAttr){
parser.parse();
});
</script>
<script>
function myOnClick(jsonObj){
if(document.getElementById("tt").checked){
var tt = new Object();
tt['name'] = "Throughput_"+jsonObj['profileName'];
tt['frameSize'] = frameSize;
require(["dojo/dom-attr", "dojo/dom"], function(domAttr, dom){
dojo.query('input[id^="tTest"]').forEach(function(node, index, arr){
alert(" ----"+node.id+" --"+dojo.byId(node.id).name);
tt[domAttr.getNodeProp(node.id,"name")] = node.value;
});
});
alert(JSON.stringify(tt));
jsonObj['throughputTest'] = tt;
}
}
</script>
感谢支持
您应该意识到,当您使用像dijit/form/NumberSpinner
这样的dijit时,您的HTML标记将被处理并转换为其他内容(=小部件)。
发生的是,你的dijit/form/NumberSpinner
,一旦解析,把名称属性在一个隐藏的字段和ID属性在另一个字段,这意味着他们不再在同一元素上可用。
当使用小部件时,您不应该再依赖HTML标记。
dijit/registry
模块获取小部件并使用它。例如,下面的命令可以工作:
registry.byId("tTestDuration").name; // Returns "testDuration"
要获取表中所有小部件的名称,可以使用dijit/registry::findWidgets()
方法,例如:
var widgets = registry.findWidgets(query("table")[0]); // Find widgets inside the table
var names = array.map(widgets, function(widget) {
return widget.name;
});
这将首先检索所有小部件对象,然后我将它们映射到一个只包含小部件名称的新数组。
看一下下面的JSFiddle: http://jsfiddle.net/6EQ75/