加入fps控制器,代码一模一样还是报错。估计是搜狗浏览器的 兼容问题,但是小白探究不出来。。。

  1. 问题如题 ,代码如下
    2.document.querySelector('#id-input-speed').addEventListener('input',function(event){
    var input = event.targt
    //log(event)
    window.fps = Number(input.value)

})
报错内容:Uncaught TypeError: Cannot read property 'value' of undefined

  1. 请问为什么这样报错
    是不是浏览器的兼容问题

  2. 如果可能 能否告知一下debug 过程呢
    谢谢。


湖上湖
浏览 473回答 1
1回答

紫衣仙女

event.target?以及选择器对应元素是input还是?补充:<!DOCTYPE html><head>&nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; <title></title></head><body>&nbsp; &nbsp; <input id="id-input-speed" type="range" value="1">&nbsp; &nbsp; <script>&nbsp; &nbsp; document.querySelector('#id-input-speed').addEventListener('change',function(event){&nbsp; &nbsp; &nbsp; &nbsp; var input = event.target&nbsp; &nbsp; &nbsp; &nbsp; console.log(input.value)&nbsp; &nbsp; &nbsp; &nbsp; window.fps = Number(input.value)&nbsp; &nbsp; })&nbsp; &nbsp; </script></body></html>代码如上,如果是兼容模式下可能会监听不到input事件,一般监听input元素还是用change事件比较普遍。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript