简体   繁体   English

onclick按钮不起作用

[英]onclick button doesn't work

I try when I click on 1 button to have the value 1 in the first(blank) button but my code doesn't work and the value of first button become 1 before I click 我尝试单击1按钮在第一个(空白)按钮中具有值1,但是我的代码不起作用,并且在单击前第一个按钮的值变为1

HTML code HTML代码

<html>
  <head>
  <title>
      Exemplu
  </title>

  </script>


  </head>
  <body>

<form>
<input type="button" value=""  id= "say_result"/>

</form>


<form>
<input type="button" value="1"  id= "say_one"/>

</form>



<form>
<input type="button" value="2"  id= "say_two"/>
</form>

<form>
<input type="button" value="+"  id= "say_plus"/>
</form>

<form>
<input type="button" value="-"  id= "say_minus"/>
</form>
<form>
<input type="button" value="="  id= "say_equal"/>
</form>

<script type="text/javascript" src=exemplu3.js></script>

</body>
  </html>

Javascript code JavaScript代码

function cifr(vallue){

var local_Value = vallue;

return  document.getElementById("say_result").value = local_Value;


}

var oneButton = document.getElementById("say_one")
oneButton.onclick = cifr(1);


function two(){
document.getElementById("say_result").value = "2";
return 2;

}

var oneButton = document.getElementById("say_two")
oneButton.onclick = two;

In the following line: 在以下行中:

oneButton.onclick = cifr(1);

You are calling the cifr function with the argument 1 and assigning the result to the oneButton click event. 您正在使用参数1调用cifr函数,并将结果分配给oneButton click事件。

This should probably be: 这可能应该是:

oneButton.onclick = function(){cifr(1);};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM