在学校,我的老师将我的代码更改为下面的示例 它不起作用,我无法理解它是如何工作并修复它的。
function _$(e, attrs) {
var el = document.createElement(e);
for(a in attrs){
el.setAttribute(a, attrs[a]);
}
}
var $taskMain = _$("section", { "class": "sdfjsf", "id": "taskId", "data-id-number": "sajfsaf"});
//and i have error
//template.js:80 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
currentCollon.appendChild($taskMain);
最佳答案
我认为您在 _$
函数末尾缺少 return el;
。
关于setAttribute 中的 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39069673/