添加文本框值并使用 javascript 显示它 [英] adding the text box values and display it using javascript

查看:27
本文介绍了添加文本框值并使用 javascript 显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 javascript 添加多个文本框的输入值并在下面显示总数.如何添加和保持计算后显示的总和.我不是 javascript 专家.

I'm trying to add the input values of several text boxes using javascript and display the total number below. How can I add and keep the sum for displaying after the computation. I'm not an expert in javascript.

推荐答案

以下示例向您展示了如何执行此操作:

Here is an example that shows you how to do this:

<form name="myFormName">
    <p><input type="text" name="myInputName1" value="25.3"></p>
    <p><input type="text" name="myInputName2" value="14.2"></p>
</form>
<div id="total"></div>

<script type="text/javascript>

    var total = parseFloat(0, 10);

    total += parseFloat(document.myFormName.myInputName1.value, 10);
    total += parseFloat(document.myFormName.myInputName2.value, 10);

    document.getElementById("total").innerHTML = "Total is " + total;

</script>

这篇关于添加文本框值并使用 javascript 显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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