【发布时间】:2021-05-31 14:34:27
【问题描述】:
每次单击按钮时,我都会尝试修改输入。有点像计算器。将从 0 开始。当我单击按钮“7”时,它的值将更改为 7,当我单击“4”时,它将更改为 74。基本上就像一个计算器。
我编写的这段代码确实修改了输入的 值,但是我似乎找不到如何追加更多值到那个值。这是我的代码。有人可以帮我吗?
<input class="normal-input" type="number" step="0.01"> <!-- Value is NULL-->
<button value="7" class="my-buttons" type="button"> 7 </button> <!--Button to change the value of the input-->
$('.my-buttons').click(function(){
$(".normal-input").attr("value", $(this).attr('value'));
}); <!-- The actual function. -->
如您所见,该函数完全用新值替换了以前的值。我希望它像计算器一样附加值。
【问题讨论】:
标签: javascript html jquery forms jquery-events