我很难在总输入字段中显示变量的内容。基本上这个代码运行起来很棒:
<script>
$(function() {
$('#product-unit-val, #total-unit-sales, #number-reps').change(function() {
var total = parseInt($("#product-unit-val").val()) *
parseInt($("#total-unit-sales").val()) *
parseInt($("#number-reps").val());
if (!isNaN(total)) {
$("#sales-val").html(total);
}
});
});
</script>
Average product unit value <input type="text" id="product-unit-val" /><br/>
Total unit sales value <input type="text" id="total-unit-sales" /><br/>
Number of reps <input type="text" id="number-reps" /><br/>
Total sales value <span id="sales-val"></span>$
但是我想在输入字段中显示总值,如:
<script>
$(function() {
$('#product-unit-val, #total-unit-sales, #number-reps').change(function() {
var total = parseInt($("#product-unit-val").val()) *
parseInt($("#total-unit-sales").val()) *
parseInt($("#number-reps").val());
if (!isNaN(total)) {
$("#sales-val").html(total);
}
});
});
</script>
Average product unit value <input type="text" id="product-unit-val" /><br/>
Total unit sales value <input type="text" id="total-unit-sales" /><br/>
Number of reps <input type="text" id="number-reps" /><br/>
Total sales value <input type ="text" id="sales-val"/>
我错过了明显的事吗?我似乎无法让这个工作。
非常感谢