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