【发布时间】:2020-07-17 15:03:46
【问题描述】:
var counter;
var count = 0;
//var booli = new Boolean("false");
window.onload = function() {
var x = document.getElementsByClassName('banana')
var i;
for (i = 0; i < x.length; i++) {
let y = x[i];
console.log(y);
x[i].onmousedown = debounce(function() {
//if(booli)
//{
start(y.className, y.value.replace(/\s/g, ''));
//};
}, 550);
};
}
function debounce(a, b) {
return function() {
var timer;
clearTimeout(timer);
timer = setTimeout(function() {
a();
}, b);
};
}
function start(clicked_className, cha) {
counter = setInterval(function() {
add(clicked_className, cha);
count++;
}, 90);
}
function end() {
//booli=false;
clearInterval(counter);
}
function add(clicked_className, cha) {
window.document.numeri.outpu.value =
window.document.numeri.outpu.value + cha;
}
#put {
width: 700px;
height: 18px;
font-size=14pt;
}
<!DOCTYPE html>
<html onmouseup="end()">
<head>
<meta charset="UTF-8">
</head>
<body>
<form name="numeri">
<input type="text" id="put" name="outpu">
<input type="button" id="apple" class="banana" value=" 1 " onmouseleave="end()">
<input type="button" id="ada" class="banana" value=" 2 " onmouseleave="end()">
<input type="button" id="aded" class="banana" value=" 3 " onmouseleave="end()">
</form>
</body>
</html>
大家好! 目标:在开始写入数字之前停止写入数字的函数 没有注释的东西程序可以工作,但它不会停止,所以我想阻止它执行用布尔值写入数字的函数。 离开按钮时必须停止 为什么它不起作用? 还有什么替代方案?
【问题讨论】:
-
代码失败的原因是什么?你有错误吗?意想不到的结果?这可能是打开浏览器调试工具并使用开发控制台和脚本调试器的好时机。
-
使用布尔变量有什么问题?顺便说一句,
new Boolean("false")应该只是false。 -
你能用
break声明吗?
标签: javascript function boolean execution