求和值 [英] Sum the value

查看:79
本文介绍了求和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个文本框必须输入用户的数字,下面我想显示用户输入的总值。如何总结并在每次输入数字时显示它?

There''s two text box that has to enter the the numbers from the user and below I want to display the total value the user inputed. How can I sum it up and have it displayed every they enter a number?

展开 | 选择 | Wrap | 行号

推荐答案

@ddtpmyra


它需要JavaScript(不是Java)亲爱的。
@ddtpmyra
It will need JavaScript (not Java) dear.
展开 | 选择 | Wrap | 行号


嘿ddtpmyra,

首先,你需要了解PHP,Java和JavaScript是什么。除了语言,他们没有别的共同点。


PHP是在服务器上执行并运行的非编译脚本。输出是纯文本(或HTML)。


Java是一种独立编译的编程语言,可以在执行的计算机上运行。


JavaScript是一种在用户网络浏览器中执行的网页中的脚本语言。


我建议您阅读教程。一个网站可以帮助您完成所有这些以及更多(并且是我们基本上已经开始使用的网站)是 www.w3schools.com 从那里开始。


至于你的问题,我会在JavaScript中这样做,因为它是微不足道的,更快的(没有刷新),而且非常简单。


为了让你感兴趣,这里有一些代码:

Hey ddtpmyra,

First you need to understand what PHP, Java, and JavaScript are. Besides languages, they have nothing else in common.

PHP is non-compiled script that is executed and run on the server. The output is plain text (or HTML).

Java is a compiled programming language that stands alone and runs on the computer it is executed on.

JavaScript is a scripting language in a web page that is executed within the user''s web browser.

My recommendation for you is to read tutorials. One site that helps you with all of this and much more (and is a site we all basically started with) is www.w3schools.com Start there.

As to your problem, I would do this in JavaScript because it''s trivial, quicker (no refresh), and pretty easy.

To get you interested, here''s some code:

展开 | 选择 | 换行 | 行号


如果您无法使hsriat的代码工作,因为它连接了值而不是对此进行求和,他犯了同样的错误,并且您将通过不调用parseInt()来实现。功能第一:


这里是更新后的工作代码:

If you had trouble getting hsriat''s code to work because it concatenated the values instead of summing this, he made the same mistake I did, and you will make by not calling the "parseInt()" function first:

here''s the updated, working code:

展开 | 选择 | 换行 | 行号


这篇关于求和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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