根据更改输入计算一个变量 [英] Calculate one variable based on changing input

查看:101
本文介绍了根据更改输入计算一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下函数:

  function updateInput(ish){ 
document.getElementById(BetAmount)。value = ish;
}

我有以下HTML输入:

 < input class =defaultTexttype =numbername =BetAmountid =BetAmountonchange = updateInput(THIS.VALUE) > 

< input type =numbername =PotentialGainid =PotentialGain/>

当用户输入一个下注金额号码( BetAmount PotentialGain ,例如,可以通过将一个常数乘以用户输入的指定下注量来找到。

我对JavaScript并不是很熟悉,因此非常感谢所有帮助!

解决方案

您的代码几乎正确 - 您在 BetAmount 字段所以没有可见的变化。



将您的代码更改为:

  document.getElementById(PotentialGain)。value = ish; 

以下是工作演示。我将事件更改为 onkeyup ,因为 onchange 仅在模糊时发生 - 即当一个领域失去焦点。


I have the following function:

function updateInput(ish){
    document.getElementById("BetAmount").value = ish;
}

I have the following HTML inputs:

<input class="defaultText" type="number" name="BetAmount" id="BetAmount" onchange="updateInput(this.value)">

<input type="number" name="PotentialGain" id="PotentialGain" />

When users enter in a bet amount number(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.

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 BetAmount field so no change is visible.

Change your code to:

document.getElementById("PotentialGain").value = ish;

Here's a working demo. I changed the event to onkeyup as onchange only happens on blur - i.e. when a field loses focus.

这篇关于根据更改输入计算一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆