dojo.attr is not returning an array but dojo.query always does. Changing code to this should help:
alert( dojo.attr( dojo.query(dojo.query(requiredItem)[0].parent('form'))[0].children('.' + settings['confirmEmailClass'])[0], 'value') );
题
I am writing a small script that validates a form.
The code below...
alert( dojo.query(dojo.query(requiredItem).parent('form')).children('.' + settings['confirmEmailClass']) );
...returns an input element as expected, however, when I try to get an attribute using it as the node that I am working on, it always returns NULL...
alert( dojo.attr( dojo.query(dojo.query(requiredItem).parent('form')).children('.' + settings['confirmEmailClass']), 'value') );
I am certain that the attribute that I am checking for exists. I am used to working with jQuery, so some of my chaining may be long winded, any tips would help.
NOTE: I am limited to using Dojo v1.6 for this project.
Thanks.
EDIT: It seams that dojo.attr() returns an array, (I guess because I'm querying by class?) and if I do...
alert( dojo.attr( dojo.query(dojo.query(requiredItem).parent('form')).children('.' + settings['confirmEmailClass'])[0], 'value') );
...I get what I am looking for. Is there a better way I should be checking for an attribute by class?
解决方案
dojo.attr is not returning an array but dojo.query always does. Changing code to this should help:
alert( dojo.attr( dojo.query(dojo.query(requiredItem)[0].parent('form'))[0].children('.' + settings['confirmEmailClass'])[0], 'value') );