Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否将this.value用作参数onload? var计数器; var计数=0; window.onload=function() { var x=document.getElementsByClassName('banana') var i; 对于(i=0;i_Javascript_Function_Event Handling_Delay_Onload - Fatal编程技术网

Javascript 是否将this.value用作参数onload? var计数器; var计数=0; window.onload=function() { var x=document.getElementsByClassName('banana') var i; 对于(i=0;i

Javascript 是否将this.value用作参数onload? var计数器; var计数=0; window.onload=function() { var x=document.getElementsByClassName('banana') var i; 对于(i=0;i,javascript,function,event-handling,delay,onload,Javascript,Function,Event Handling,Delay,Onload,this.className,this.value 我想问题就在这里,因为如果我用'1'交换这个.value,它就可以工作了 在这种情况下,this.value和/或this.className有什么问题 还有一种更优雅的方法可以在按键上添加初始延迟,然后在迭代之间添加延迟吗?在你的函数中,这个引用了窗口。onload函数没有任何值。我猜您想使用x[I]。value而不是这个。value谢谢:)是有道理的,但是现在我没有得到任何输出,错误是:“Uncaught TypeError:x[I]未定义

this.className,this.value 我想问题就在这里,因为如果我用'1'交换这个.value,它就可以工作了

在这种情况下,this.value和/或this.className有什么问题


还有一种更优雅的方法可以在按键上添加初始延迟,然后在迭代之间添加延迟吗?

在你的函数
中,这个
引用了
窗口。onload
函数没有任何
值。我猜您想使用
x[I]。value
而不是
这个。value

谢谢:)是有道理的,但是现在我没有得到任何输出,错误是:“Uncaught TypeError:x[I]未定义”,而不是未定义的输出
<!DOCTYPE html>
<html onmouseup="end()">
<head>
    <meta charset="UTF-8">
</head>


<script>
var counter;
var count = 0;

window.onload=function()
{
var x=document.getElementsByClassName('banana')
var i;
for (i = 0; i < x.length; i++)
    {
        x[i].onmousedown = debounce(function()
        {
        start(this.className,this.value);  //////if i put '1' instead of this.value it works
        }, 550);
    }
}


function debounce(a, b)
{
    var timer; 
    return function()
    {
        clearTimeout(timer); 
        timer = setTimeout(function()
        {
            a(); 
        }, b); 
    };
}

function start(clicked_className,cha)
  {
    counter = setInterval(function()
    {
      add(clicked_className,cha);
      count++;
    },90);
  }
  function end()
  {
    clearInterval(counter);
  }

function add(clicked_className,cha)
{
window.document.numeri.outpu.value =
window.document.numeri.outpu.value + cha;


}

</script>

<body>
<form name="numeri">
<input type="text"name="outpu">
<input type="button"id="apple"class="banana"value=" Click & Hold  "onmouseleave="end()">
</form>
</body>

</html>