我收到此错误:Cannot read property 'getBoundingClientRect' of null。我使用这个功能getBoundingClientRect,是因为在我的项目中我想要达到以下效果:当一个元素突出显示时,其余元素具有不同的样式。该消息显示了功能handleScroll。我使用的组件看起来像这样
class QuestionListItem extends Component {
constructor() {
super();
this.state = {
isActive: false,
};
this.handleScroll = this.handleScroll.bind(this);
}
componentDidMount = () => {
window.addEventListener('scroll', this.handleScroll);
this.handleScroll();
};
handleScroll = () => {
const { isActive } = this.state;
const { top } = this.wrapRef.getBoundingClientRect();
if (top > 60 && top < 400 && !isActive) {
this.setState({ isActive: true });
}
if ((top <= 60 || top >= 400) …Run Code Online (Sandbox Code Playgroud) 我正在尝试解决此任务:
ATM 机允许 4 位或 6 位 PIN 码,PIN 码只能包含 4 位或 6 位数字。
如果函数传递了一个有效的 PIN 字符串,则返回 true,否则返回 false。
例如:
validatePIN("1234") === true validatePIN("12345") === false validatePIN("a234") === false
这是我的代码:
function validatePIN (pin) {
if(pin.length === 4 || pin.length === 6 ) {
if( /[0-9]/.test(pin)) {
return true;
}else {return false;}
}else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
它表明 --- 'a234' 的输出错误 - 预期:false,而不是得到:true ---为什么?这个 /[0-9]/ 只显示数字?
先感谢您 :)
我有两种功能,一种是通过单击开始按钮触发的
function startGame() {
setInterval(setCellPosition, 3000);
setTimeGame = setTimeout(startGame, 2000);
setTime();
};
Run Code Online (Sandbox Code Playgroud)
第二个,单击重置按钮后将被调用
function resetGame() {
scoreBox.innerHTML = "0";
timeBox.innerHTML = "60";
liveBox.innerHTML = "3";
clearTimeout(setTimeGame)
};
Run Code Online (Sandbox Code Playgroud)
该resetGame功能不起作用。值(得分,时间,实时)被重设,但startGame功能不会停止。如何解决?如何停止startgame功能?