【发布时间】:2017-09-18 17:59:31
【问题描述】:
我正在尝试使用 AngularJS 应用程序中的以下 sn-p 代码使用 JavaScript 选择一个元素。
var assicurazione = document.getElementsByClassName("assicurazione");
var aLength = assicurazione.length;
for(var key in assicurazione){
console.log("key: ", key);
console.log("assicurazione[key] ", assicurazione[key]);
}
console.log("assicurazione element: ", assicurazione);
console.log("assicurazione.length: ", aLength);
for(var a = 0; a < aLength; a++){
console.log("Element: ", assicurazione[a]); // not firing
console.log("a value: ", a); // not firing
}
console.log 的输出如下:
循环没有按预期工作,因为长度为 0,但元素有一个长度属性,在这种情况下,它设置为 16,所以我不知道为什么它不会循环遍历元素。
谁能帮帮我?
【问题讨论】:
-
循环正常,你有什么问题?
-
assicurazione 元素的行为不符合预期。
-
'如预期'是什么意思?您对它的工作方式有何期望?
-
一切正常,如您所见:jsfiddle.net/zt1cpa9q您的问题是什么?
-
上传更多图片和代码
标签: javascript html angularjs dom