【问题标题】:Jquery : multiply two text fields and update into 3rd text fieldJquery:将两个文本字段相乘并更新为第三个文本字段
【发布时间】:2012-07-03 07:19:28
【问题描述】:

这里我有 3 个文本字段被视为 a1、a2 和 a3,现在我需要将 a1 * a2 的值相乘并将答案更新到第三个字段。我怎么能用 jquery 做到这一点?我们在 jquery 中有任何更新功能吗?

【问题讨论】:

    标签: jquery textfield


    【解决方案1】:

    假设 a1、a2 和 a3 是这样的元素的 id

    <input id="a1" type="text" value="10" />
    <input id="a2" type="text" value="20" />
    <input id="a3" type="text" value="" />
    

    那么您所要做的就是将其添加到页面中

    $(document).ready(function(){
        $('#a1').keyup(calculate);
        $('#a2').keyup(calculate);
    });
    function calculate(e)
    {
        $('#a3').val($('#a1').val() * $('#a2').val());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-30
      • 1970-01-01
      • 2019-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多