单击事件后值消失 [英] Value disappears after click event
本文介绍了单击事件后值消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用带有 onclick 事件的 javascript 制作计算器我希望按钮的值转换输入文本框.当我写代码时,按钮的值在文本框中短暂显示,但它立即消失了.
I try to make a calculator with javascript with the onclick event I want the value of the button to convert an input text box. When I write the code the value of the button briefly in the text box , but it disappears instantly.
您可以在本文下方找到我使用的代码,我做错了什么.
HTML:
The code that i use can you find below this text, what am i doing wrong.
HTML:
var iGetal = 0;
function GetalRekenmachine()
{
iGetal = iGetal + 1;
document.getElementById("Display").value = iGetal;
}
<button id="Cijfer7" value="7" onclick="GetalRekenmachine()">7</button>
<input type="text" id="Display"/>
推荐答案
因为按钮的默认类型是提交.所以要么取消点击动作,要么设置类型为按钮.
Because the default type of a button is submit. So either cancel the click action or set the type to be button.
<button id="Cijfer7" value="7" onclick="GetalRekenmachine(); return false;">7</button>
或
<button type="button" id="Cijfer7" value="7" onclick="GetalRekenmachine()">7</button>
这篇关于单击事件后值消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文