我想在下面的小部件中添加多个类以用于样式目的:
var filteringSelect = new dijit.form.FilteringSelect({
id: "test",
},
"test");
我将如何做到这一点?
这是实际的html:
<div tabindex="-1" wairole="combobox" dojoattachpoint="comboNode" dojoattachevent="onmouseenter:_onMouse,onmouseleave:_onMouse,onmousedown:_onMouse" id="widget_test" class="dijit dijitReset dijitInlineTable dijitLeft dijitComboBox" role="combobox" widgetid="test">
<div style="overflow: hidden;">
<div dojoattachevent="onmousedown:_onArrowMouseDown,onmouseup:_onMouse,onmouseenter:_onMouse,onmouseleave:_onMouse" wairole="presentation" dojoattachpoint="downArrowNode" class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton" role="presentation">
<div class="dijitArrowButtonInner">
 
</div>
<div class="dijitArrowButtonChar">
▼
</div>
</div>
<div class="dijitReset dijitValidationIcon">
<br>
</div>
<div class="dijitReset dijitValidationIconText">
Χ
</div>
<div class="dijitReset dijitInputField">
<input type="text" waistate="haspopup-true,autocomplete-list" wairole="textbox" dojoattachpoint="textbox,focusNode" dojoattachevent="onkeypress:_onKeyPress,compositionend" class="dijitReset" autocomplete="off" role="textbox" aria-haspopup="true" aria-autocomplete="list" aria-invalid="false" id="test" tabindex="0" aria-required="true" value="United States"><input type="text" style="display: none;" name="">
</div>
</div>
</div>
答案 0 :(得分:9)
dojo.addClass(filteringSelect.domNode, "yourClass");
这也处理DOM节点已经包含“youClass”作为CSS类的情况,以便不添加重复项。 dojo还提供了使用dojo.removeClass()和dojo.toggleClass()来处理CSS类管理的其他方法。
http://staging.dojotoolkit.org/reference-guide/dojo/addClass.html
答案 1 :(得分:2)
进一步的工作方法:
(1)程序版本,从脚本创建小部件:
var filteringSelect = new dijit.form.FilteringSelect({
id: "test",
class: "myClassName"
},
"test");
(2)如果你只设置了“class”属性,它会调用dijit/_WidgetBase.js
setter函数_setClassAttr
,它完全符合你的要求:
<div data-dojo-type="dijit/form/SomeThing" class="myClassName"></div>
(3)您可以设置窗口小部件的dojo属性,如下所示:
<div data-dojo-type="dijit/form/SomeThing" data-dojo-props="class: 'myClassName'"></div>