运行querySelector时我什么也没得到。当我尝试登录el时,它可以工作,但是查询选择器不起作用!我最后移动了js文件,但仍无法正常工作
El正在传递,但是我的查询选择器不起作用!
(function(global) {
let SimpleShow = function(el) {
return new SimpleShow.init(el);
}
SimpleShow.init = function(el) {
this.slider = document.querySelector(el);
//This code isn't working. Nothing is being selected
console.log(this.slider);
//However this is working. El is being passed around
console.log(el);
}
global.SimpleShow = SimpleShow;
}(window));
let slideshow = SimpleShow("#gallery");
ul {
list-style-type: none;
}
.box1 {
height: 400px;
width: 700px;
background: red;
}
.box2 {
height: 400px;
width: 700px;
background: black;
}
.box3 {
height: 400px;
width: 700px;
background: green;
}
.box4 {
height: 400px;
width: 700px;
background: wheat;
}
<div id="gallery">
<ul>
<li class="box1"></li>
<li class="box2"></li>
<li class="box3"></li>
<li class="box4"></li>
</ul>
</div>