我想将 gc 值乘以每个计数类,并且我想在 id total 的输入字段中进行总计。 gc 值取自 db
<script>
jQuery.noConflict();
$(document).ready(function(){
calculateSum();
$(".count").keyup(calculateSum);
});
function calculateSum() {
var sum = 0;
console.log('called');
$(".count").each(function() {
console.log(this.value);
if(!isNaN(this.value) && this.value.length!=0) {
sum += parseFloat(this.value);
}
});
$("#total").val(sum);
}
</script>
<input type='text' id='gc' name='gc' value="<?php echo $gc; ?>">
<input class='count'>
<input class='count'>
<input class='count'>
<input class='count'>
<input id='total'>
最佳答案
您的代码应该如下所示以乘以值
function calculateSum() {
var sum = 0;
console.log('called');
$(".count").each(function() {
console.log(this.value);
if(!isNaN(this.value) && this.value.length!=0) {
sum += parseFloat(this.value * $("#gc").val());
}
});
$("#total").val(sum);
}
希望这有助于...
关于javascript - jquery输入的乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24675004/