我无法在需要帮助的范围内获得a和b
我需要找到c来完成我的代码和想法
.html
<div id ='hours'></div>
.js
var h = document.getElementById('hours');
h.onmousedown = (e) => {var a = e.clientX; console.log('in' ,e.clientX);}
h.onmouseup = (e) =>{var b = e.clientX; console.log('out' , e.clientX); }
var c = a - b ;
答案 0 :(得分:1)
在代码的开头定义a
和b
。
var h = document.getElementById('hours');
var a,b;
h.onmousedown = (e) => {a = e.clientX; console.log('in' ,e.clientX);}
h.onmouseup = (e) =>{b = e.clientX; console.log('out' , e.clientX); }
var c = a - b ;