0
순수 JS에 코드를 작성하고 싶습니다.바닐라 js의 현재 위치
var linx = document.querySelectorAll(".navbar a");
for (var i = 0; i < linx.length; i++) {
if (linx[i].getAttribute('href') == document.location.pathname) {
this.className += ' active';
}
}
LINX [I] .getAttribute ('HREF') == document.location.pathname
가 출력 true/false
다음 콘솔
때문에 문제는 안쪽 if
성명서, 나는 틀린 것을 얻을 수 없다.
디버그 조건 :'을 console.log (I, LINX [i]를 .getAttribute ('HREF'), document.location.pathname)' – epascarello
속성 'getAttribute를'정의의 (...)를 읽을 수 없습니다 –
그래서 한 내 코드로 오류가 발생합니까? for 루프 안에 배치하지 않았습니까? – epascarello