是否存在依赖问题?
因为我使用的是唯一的纯 javascript,所以没有 jquery 或任何东西。
使用node.js
这是我的代码
window.onload()=function(){
var left=document.querySelector('.left');
var right=document.querySelector(".right");
var container=document.querySelector(".container");
console.log(left);
left.addEventListener('mouseenter',()=>{
container.classList.add('hover-left');
})
left.addEventListener('mouseleave', () => {
container.classList.remove('hover-left');
})
right.addEventListener('mouseenter', () => {
container.classList.add('hover-right');
})
right.addEventListener('mouseleave', () => {
container.classList.remove('hover-right');
})
}
<div class="container">
<div class="split left">
<h1>The Designer</h1>
<a href="" class="button">Read more</a>
</div>
<div class="split right">
<h1>The Programmer</h1>
<a href="" class="button">Read more</a>
</div>
</div>
最佳答案
我在 Chrome 上遇到此错误:
Uncaught TypeError: window.onload is not a function
删除括号,错误就消失了。
但我不知道你的页面应该如何工作。
在此处查找更多信息:
关于javascript - document.querySelector() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50174544/