JavaScript 数学方程
我有两个表单字段 money
和 years
,需要将数字输出到第三个字段 cv
。
理想情况下,当输入第一个数字时,但我也同意按下按钮后发生这种情况,
<FORM name="salary">
<input type="number" size=12 name="money">
<input type="number" size=12 name="years">
<input type="number" size=12 name="cv">
</FORM>
涉及的数学如下。
(金钱 * 年数)-(金钱 * 年数)x = 简历
其中:
- x 等于 0 如果年数等于 1
- x 等于 .2 如果年数等于 2
- x 等于 .45 如果年数等于 3
- x 等于 .6 如果年数等于 4
- x 等于 .2。如果年数等于 5,则为 65
- x 如果年数等于 6,则等于 0.75
I have two form fields money
and years
that need to output a number into a third field cv
.
Ideally while the first numbers are being entered but I'm OK with it happening after a button is pressed as well
<FORM name="salary">
<input type="number" size=12 name="money">
<input type="number" size=12 name="years">
<input type="number" size=12 name="cv">
</FORM>
The math involved would be the following.
(money * years) - (money * years) x = cv
Where:
- x equals 0 if years equals 1
- x equals .2 if years equals 2
- x equals .45 if years equals 3
- x equals .6 if years equals 4
- x equals .65 if years equals 5
- x equals .75 if years equals 6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
分解问题,您需要知道如何使用 javascript 来:
所有这些以及更多内容都可以找到 此处。
Breaking the problem down, you need to know how to use javascript to:
All that and much more can be found here.
您可以使用 jQuery,在这种情况下,它将是这样的:
You can use jQuery, in which case it'll be something like this:
您需要在人们输入数据的两个字段上放置一个 onKeyUp() 事件,并调用如下所示的函数,此外还向函数中使用的每个字段添加一个 id。 如果您不使用prototype或jquery,则需要使用 getElementById('var') 代替 $('var')
Your going to want to put an onKeyUp() event on both of the fields people enter the data into and call a function something like what follows, in addition add an id to each field as used in the function. If you are not using prototype or jquery you need to use getElementById('var') in place of the $('var')
计算一下:
在 http://jquery.com/ 获取 jQuery
像这样更新你的代码(注意名称 → ID):
Do the math:
Get jQuery at http://jquery.com/
Update your code like this (notice that name → id):