0

a=dojo.query('label');

by this command i get

<label id=​"labelforclientname">​
                Client name
            ​&lt;/label>​
, 
<label id=​"labelforphysical">​
                Physical 
                ​&lt;/label>​
, 
<label id=​"labelforpostal">​
                Postal 
                ​&lt;/label>​
, 
<label id=​"labelfortele">​
                Telephone No 
                ​&lt;/label>​
, 
<label id=​"labelforfax">​
                Fax No
                ​&lt;/label>​
, 
<label id=​"labelformail">​
                Email
                ​&lt;/label>​
, 
<label id=​"labelforaddress">​
                Address to :
            ​&lt;/label>​

that is all the label in my form

now i want to access each label id. is it possbile in dojo ?

4

2 回答 2

0

您还可以通过以下方式访问标签:

require(["dojo/dom"], function(dom){
    // fetch a node by id="someNode"
    var node = dom.byId("someNode");
});
于 2012-10-09T09:18:53.463 回答
0

id如果您只想要一个带有s的数组,那么map()这是最直接的方法:

// map
var ids1 = dojo.query('label').map(function(label) {
    return label.id
});

或使用forEach

// forEach
var ids2 = [];
dojo.query("label").forEach(function(label) {
    // do whatever you need with a label here
    ids2.push(label.id);          
});

在 jsFiddle 上查看它的实际效果:http: //jsfiddle.net/phusick/nfMGC/

dojo/query返回dojo/NodeList它是一个类似数组的对象,它为链接添加语法糖。您可以使用它的许多方法,例如filterstyletoggleClass。有关其他详细信息,请参阅使用 dojo/queryNodeList 扩展教程。

于 2012-10-09T07:41:03.443 回答