HTML attribute comparison
How would you code a if conditional check in dojo?
if(!dojo.query("#idOfHhtmlField").attr("disabled") == true)
{
//do something
}
Here I am trying to compare if #idOfHhtmlField
's disabled attribute is set开发者_StackOverflow to true or not, but it doesnt seem to be working for me.
i tested this html in dojo,here:
<button id="test0" disabled>button0</button>
<button id="test1" disabled="disabled">button1</button>
<button id="test2" disabled="false">button2</button>
<div id="test3" disabled>div0</div>
<div id="test4" disabled="disabled">div1</div>
<div id="test5" disabled="false">div2</div>
since you can set div's disabled in ie8, so it returns all true. but in chrome only the buttons return true. you should check if #idOfHhtmlField is a form element .
update
i suggest you detect disabled this way,because browsers do not need its value:
if(dojo.hasAttr("id",'disabled')){
//alert(123)
}
i know little about dojo , because dojo.query().attr() returns an object,it is weired! and here is the official guide.
if(!dojo.query("#idOfHhtmlField").disabled) {
...
}
Is idOfHhtmlField
a DOM element (div, span, input etc)? or is it a dijit widget?
If it is a DOM node, you might want to use:
var field = dojo.byId('idOfHtmlField');
console.log(field.disabled);
If you are using a dijit widget of some type (either programmatic instantiation or declarative via dojoType or data-dojo-type), you will want to use:
var fieldWidget = dijit.byId('idOfHtmlField');
var isDisabled = fieldWidget.get('disabled');
console.log(isDisabled);
精彩评论