-1
我有一個函數來實際創建一個HTML元素並快速綁定它。爲什麼如果我的函數中的作用域被JavaScript解釋器完全忽略了?
然而,它不工作,因爲它應該。
當我使用調試(ggCreateElement)時,我發現即使語句爲「true」,它也會完全跳過if
範圍。我已經用完了想法。
function ggCreateElement(tagName,className,idName,appendPointTagName) {
d=document.createElement(tagName);
d.className=className;
d.id=idName;
ap=document.getElementsByTagName(appendPointTagName);
if (ap.lenght==0) {
console.log("Append point tag name is not found ! ") ;
}
else {
ap[0].appendChild(d);
return d;
}
}
請問您能幫我嗎?謝謝。
如何你調用它嗎? – Rayon
'ap.lenght'?你正在粘貼正確的代碼嗎?也''console.log(ap.length);'在if塊之前 –
調試時'ap.lenght'的值是多少? – Paddy