1
我有数量的价格表。如果我在输入中输入数量并从下拉菜单中选择颜色并选择产品和价格,则需要计算总数。首先,我需要一些数量和颜色的价格。其次,支票号码在表格数量栏中。输入必须是最小的30.例如:如果数字299 - 数量是200,如果4300 - 数量是3000等等更小。还有就是我的表和jQuery:如何计算jquery总数?
var total = $("#Total").val();
var table = Array();
$("table.quantity tr td:nth-child(1)").each(function (i, v) {
table[i] = $(this).text();
});
console.log(table);
$('#Quantity').on("input", function() {
var quantity = this.value;
var count = 0;
if (quantity >= 30) {
$.each(table, function (i, value) {
if (quantity >= parseInt(value)) {
count = value;
};
});
console.log(count);
}
});
$('#select-model').on('change', function(){
var price = $('option:selected', this).data('price');
if (total == '') {
total = 1;
}
$("#Total").val(price * total);
});
我认为数组必须是这样的:
Array
(
[30] => Array
(
[1] => 1.4
[2] => 1.7
...
[8] =>
)
[50] => Array
(
[1] => 1.1
[2] => 1.3
...
[8] => 2.4
)
...
[5000] => Array
(
[1] => 0.3
[2] => 0.35
...
[8] => 1
)
)
有我的代码:http://jsfiddle.net/Dewilas/cz69vL8u/
总的结果是:
为前。 :6.59 * 5000 * 0.3 (产品1 *数量5000 *颜色1)
谢谢,但不正确。你计算数量*颜色计数(例如:30 * color2 = 60),但我需要计数数量* color2值(30 * 1.7)。为什么我需要与colums价值数组 – Haroldas