dimas15,
закоментирован в коде вариант любезно предложенный
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>spinner demo</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<style type="text/css">
.spinner{
width: 50px
}
span{
color: #FF0000;
}
</style>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
<body>
<table>
<tr>
<td>Формула 1 за 1шт <span>828</span> руб</td>
<td>Кол-во шт.: <input type="text" name="spinner" min="0" value="0" id="spinner" class="spinner" data-price="828"/></td>
</tr>
<tr>
<td>Формула 2 за 1шт <span>750</span> руб</td>
<td>Кол-во шт.: <input type="text" name="spinner" min="0" value="0" id="spinner2" class="spinner" data-price="750"/></td>
</tr>
<tr>
<td>Формула 3 за 1шт <span>650</span> руб</td>
<td>Кол-во шт.: <input type="text" name="spinner" min="0" value="0" id="spinner3" class="spinner" data-price="650"/></td>
</tr>
<tr>
<td>...</td>
<td>....</td>
</tr>
<tr><td>Общая стоимость: <span id="res_total" name="priceall"></span></td></tr>
</table>
<input id="spinner">
<script>
var sum = [],
total = function (a) {
return a.reduce(function (a, b, c) {
return a + b
}, 0)
};
$("[name='spinner']").each(function (indx, el) {
//var price = +$('span', $(el).parents('tr')).html();
var price = +$(el).data('price');
sum[indx] = 0;
$(el).spinner({
spin: function (event, ui) {
sum[indx] = ui.value * price;
$("#res_total").html(total(sum))
},
change: function (event, ui) {
sum[indx] = this.value * price;
$("#res_total").html(total(sum))
},
stop: function (event, ui) {
sum[indx] = this.value * price;
$("#res_total").html(total(sum))
}
});
});
$("#res_total").html(total(sum))
</script>
</body>
</html>
|