javascript - jquery 乘以 2 个文本框然后显示解决方案

标签 javascript jquery multiplication

我的代码不起作用。我试图将两个文本框相乘并显示解决方案,但当我单击时它没有显示任何内容。到目前为止我的代码是这样的...下面的代码有什么问题?

<script type="text/javascript">
    $('#AddProduct').click(function() {
        var totalPrice = $('#debt').val() * $('#income').val();
        $('#solution').val() = totalPrice;
    });
</script>

<form name="form" method="post" action="">
    <table>
        <tr>
            <td><input type="text" name="income" id="income" /></td>
            <td><input type="text" name="debt" id="debt" /></td>
            <td><input type="text"  id="solution"  name="solution" /> </td>
        </tr>
  </table>
</form>

最佳答案

你的 jQuery 需要是:

$('#AddProduct').click(function() {
   var totalPrice = parseInt($('#debt').val()) * parseInt($('#income').val()); // you can't multiply strings
   $('#solution').val(totalPrice); // This is how you use .val() to set the value.
});

关于javascript - jquery 乘以 2 个文本框然后显示解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14914458/

相关文章:

javascript - JavaScript 中的自定义 "confirm"对话框?

javascript - 专注于输入并使用 Jquery 移除焦点

javascript - 带有 jquery 的子菜单无法正常工作

javascript - 在新插件中使用 attr() 函数?

python pandas dataframe 乘以匹配索引或行名称的列

javascript - 在 For 循环中乘以整数

javascript - 没有 'Access-Control-Allow-Origin' header ,但无法访问 API

javascript - 一系列下拉菜单,由 jQuery 提供支持,可以隐藏和显示,但在 Chrome 中不行

php - 使 jQuery UI 自动完成源依赖于另一个自动完成

c++ - 或 C++ : VS2010 multiplication operator being mistaken for a null pointer