jQuery-乘以3个输入字段并自动填充第4个输入 [英] JQuery - Multiply 3 input fields and auto populate the 4th input

查看:71
本文介绍了jQuery-乘以3个输入字段并自动填充第4个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个输入字段:

<input type="text" name="height" /> * <input type="text" name="width" /> *<input type="text" name="length" />
and the total:
= <input type="text" name="total" />

如何处理将自动填充总字段的jQuery?

how to do with jQuery that will auto populate the total field?

谢谢!

推荐答案

首先,您应该在输入中添加id:

First, you should add id to your inputs:

<input type="text" id="txt1" ... /> 
// also for 2, 3 and 4 ...

然后,您可以简单地添加以下jquery事件以动态计算结果:

Then, you can simply add this jquery event to dynamically calculate the result:

<script>
    $(document).ready(function () { 
        $("#txt1, #txt2, #txt3").change(function() {
            $("#txt4").val($("#txt1").val() * $("#txt2").val() * $("#txt3").val());
        });
    });
</script>

这篇关于jQuery-乘以3个输入字段并自动填充第4个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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