我在一个小部件中有这个JS代码,它可以在小部件加载的页面上正常工作。但是错误(" new.js?ver = 0.0.1:92 Uncaught TypeError:无法读取属性' querySelector' of null")页面上的小部件不是显示在这里的jS代码 -
const char vShaderStr[] =
"#version 300 es \n"
"uniform mat4 u_mvpMatrix; \n"
"layout(location = 0) in vec4 a_position; \n"
"layout(location = 1) in vec4 a_color; \n"
"out vec4 v_color; \n"
"void main() \n"
"{ \n"
" v_color = a_color; \n"
" gl_Position = u_mvpMatrix * a_position; \n"
"} \n";
const char fShaderStr[] =
"#version 300 es \n"
"precision mediump float; \n"
"in vec4 v_color; \n"
"layout(location = 0) out vec4 outColor; \n"
"void main() \n"
"{ \n"
" outColor = v_color; \n"
"} \n";
userData->programObject = esLoadProgram ( vShaderStr, fShaderStr );
据我所知,因为小部件没有加载其他页面因此错误,但我如何解决错误?尝试但没有工作
var
carousel = document.querySelector('.threedcarousel'),
figure = carousel.querySelector('figure'),
nav = carousel.querySelector('nav'),
numImages = figure.childElementCount,
theta = 2 * Math.PI / numImages,
currImage = 0
;
nav.addEventListener('click', onClick, true);
function onClick(e) {
e.stopPropagation();
var t = e.target;
if (t.tagName.toUpperCase() != 'BUTTON')
return;
if (t.classList.contains('next')) {
currImage++;
}
else {
currImage--;
}
figure.style.transform = `rotateY(${currImage * -theta}rad)`;
}
答案 0 :(得分:0)
发布答案。
我一直在寻找在特定页面而非所有页面上触发事件的方法。我最终使用-
在page1.php中,您有一个$(document).ready(onPage1Load),对于其他页面,依此类推。这样可以确保未注册意外事件处理程序。