0
我试图创建一个html5视频音量操作,并且我想使用javascript将其插入DOM
,但是当我使用for
循环浏览元素时,它会返回undefined
。 这是我的代码:创建元素是undefined
// Volume
var volumeWrapper = document.createElement('span');
volumeWrapper.className = "volumeWrapper";
insertAfter(elapseTimeWrapper, volumeWrapper);
for (var i = 0; i <= 4; i ++) {
var volumeControl = document.createElement('span');
volumeWrapper.appendChild(volumeControl);
(function(index) {
volumeControl.onclick = function() {
if (this.className == "") {
this.className = "active";
for (var j = 0; j <= index; j ++) {
console.log(volumeControl[j]) // return undefined
}
} else {
this.className = "";
}
}
})(i);
}
我不知道什么是错的代码,当我直接插入到HTML,它不是undefined
。它返回精灵的确切值。我想插入它使用JavaScript不是HTML。我需要你的帮助。 非常感谢您的回复。
我在我的代码中创建了这个函数。 – 2014-11-04 07:37:31
谢谢你的帮助!我没想过为我的代码添加一个ID。你的代码运行完美! :d – 2014-11-04 07:50:10