Uncaught TypeError: Object [object HTMLDivElement] has no method 'setAttribute' 当我尝试在对象中添加一个元素的 id 时,我不断收到此错误。
这是对我来说很糟糕的台词
dojo.attr(query(".toggle_section", object),"id",i);
function toggleClass(){
require(["dojo/on",
"dojo/query",
"dojo/dom-class"
],
function(on, query, domClass) {
query(".toggle-container").forEach(function(object, i){
var btn_toggle = query(".toggle", object);
dojo.attr(query(".toggle_section", object),"id",i);
on(btn_toggle, "click", function(evt){
domClass.toggle(object, "closed");
evt.preventDefault();
});
});
});
}
<div class="toggle-container">
<a class="toggle" href="#" title="toggle profile">PROFILE</a>
<div class="toggle_section">
<p>hidden content</p>
</div>
</div>