내 코드가 작동하지 않는 이유를 파악하는 데 어려움을 겪고 있습니다.Javascript - 'getElementsByClassName'이 작동하지 않음
다음function init() {
var showMenu = document.getElementsByClassName('showMenu'),
perspectiveWrapper = document.getElementById('perspective'),
container = perspectiveWrapper.querySelector('.container'),
contentWrapper = container.querySelector('.wrapper');
showMenu.addEventListener(clickevent, function(ev) {
ev.stopPropagation();
ev.preventDefault();
docscroll = scrollY();
// change top of contentWrapper
contentWrapper.style.top = docscroll * -1 + 'px';
// mac chrome issue:
document.body.scrollTop = document.documentElement.scrollTop = 0;
// add modalview class
classie.add(perspectiveWrapper, 'modalview');
// animate..
setTimeout(function() { classie.add(perspectiveWrapper, 'animate'); }, 25);
});
}
는 HTML의 일부입니다 : 다음은 JS의 일부입니다
TypeError: undefined is not a function (evaluating 'showMenu.addEventListener')
I :
<div id="topBar">
<h1>Company</h1>
<a href="#" class="entypo-menu showMenu"></a>
</div>
<div class="line"></div>
<div id="fixedBar">
<h1>Company</h1>
<a href="#" class="entypo-menu showMenu"></a>
</div>
내가 페이지를로드 할 몇 가지 이유를 들어,이 오류가 발생합니다 이 줄을 변경하면 이해할 수 없습니다.
var showMenu = document.getElementsByClassName('showMenu'),
to :
var showMenu = document.getElementById('showMenu'),
작동하지 않습니다!
클래스 선택기가 작동하지 않지만 ID가 작동하지 않는 이유는 무엇입니까? JS를 수행하기 위해 클래스 showMenu
과 함께 두 링크를 가져 오려고합니다.