我正在用dojo 1.6编写一个可以修改属性值的Dojo函数:
function replaceAttributeDojo(obj, attrName, newValue) {
var value = dojo.getAttr(obj, attrName);
if (value !== 'undefined') {
//console.log('Found attribute '+attrName+' on object '+obj.attr('nodeName')+'[id='+obj.attr('id')+', name='+obj.attr('name')+', widgetid='+obj.attr('widgetid')+']');
if (value == '') {
//console.log('Attribute value is empty, removing the attribute');
//obj.removeAttr(attrName);
return;
}
var newAttrValue = value.replace(/[\d]+/g, newValue);
dojo.setAttr(obj, attrName, newAttrValue);
} else {
//console.log('Did not find attribute '+attrName+' on object '+obj.attr('nodeName')+'[id='+obj.attr('id')+', name='+obj.attr('name')+', widgetid='+obj.attr('widgetid')+']');
}
}跟踪代码并找到此行上丢失的firebug
var value = dojo.getAttr(obj, attrName);它告诉我
dojo.getAttr is not a function该函数在dojo.ready外部定义,但在dojo.ready()内部调用。
下面是在dojo.ready()中调用函数的部分
dojo.query("div, input, select", row).forEach(function(){
replaceAttributeDojo(row, 'id' , index);
replaceAttributeDojo(row, 'name' , index);
replaceAttributeDojo(row, 'widgetid' , index);
});dojo.ready()中同一页面上的所有东西都工作得很好,那么这怎么可能呢?
发布于 2013-03-21 03:25:26
如果obj是DOM节点:
var val = dojo.attr(node, attrName); // getter
dojo.attr(node, attrName, newValue); // setterhttp://dojotoolkit.org/reference-guide/1.6/dojo/attr.html
如果obj是一个Widget:
var val = widget.get(attrName); // getter
widget.set(attrName, newValue); // setterhttp://dojotoolkit.org/reference-guide/1.8/dijit/_WidgetBase.html
https://stackoverflow.com/questions/15532660
复制相似问题