根据更改输入计算一个变量 [英] Calculate one variable based on changing input
问题描述
我有以下函数:
function updateInput(ish){
document.getElementById(BetAmount)。value = ish;
}
我有以下HTML输入:
< input class =defaultTexttype =numbername =BetAmountid =BetAmountonchange = updateInput(THIS.VALUE) >
< input type =numbername =PotentialGainid =PotentialGain/>
当用户输入一个下注金额号码( 我对JavaScript并不是很熟悉,因此非常感谢所有帮助! 您的代码几乎正确 - 您在 将您的代码更改为: 以下是工作演示。我将事件更改为 I have the following function:
I have the following HTML inputs:
When users enter in a bet amount number( I'm not very familiar with JavaScript, so any help is greatly appreciated! Your code is almost correct - you are showing the result in the Change your code to: Here's a working demo. I changed the event to 这篇关于根据更改输入计算一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! BetAmount $ c $我想立即显示一个计算出的
PotentialGain
,例如,可以通过将一个常数乘以用户输入的指定下注量来找到。
BetAmount $ c $中显示结果c>字段所以没有可见的变化。
document.getElementById(PotentialGain)。value = ish;
onkeyup
,因为 onchange
仅在模糊时发生 - 即当一个领域失去焦点。function updateInput(ish){
document.getElementById("BetAmount").value = ish;
}
<input class="defaultText" type="number" name="BetAmount" id="BetAmount" onchange="updateInput(this.value)">
<input type="number" name="PotentialGain" id="PotentialGain" />
BetAmount
), I would like to instantly show a calculated PotentialGain
, which, for example, can be found by multiplying a constant by the specified bet amount entered in by the user.BetAmount
field so no change is visible.document.getElementById("PotentialGain").value = ish;
onkeyup
as onchange
only happens on blur - i.e. when a field loses focus.