Замена значения в массиве
Доброе время суток форумчане!!)))
Помогите пожалуйста разобраться с одной проблемой.. уже не один час потратил на вроде простую задачу :( Есть Range <input class="rangenain" id="term1" type="range" step=1 min="1" max="10" value="7"> есть код js
function negative() {
negativeUp = [ priceDifference(), 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
return negativeUp
};
function positive() {
positiveUp = [ 0, tcoSavings(), tcoSavings(), tcoSavings(), tcoSavings(), tcoSavings(), tcoSavings(), tcoSavings(), tcoSavings(), tcoSavings() ];
return positiveUp
};
function ice() {
iceUp = [ analoguePlatform.onchange(), analogueTco(), analogueTco(), analogueTco(), analogueTco(), analogueTco(), analogueTco(), analogueTco(), analogueTco(), analogueTco()];
return iceUp
};
function charge() {
chargeUp = [ chargeTruckPrice(), chargeTco(), chargeTco(), chargeTco(),
chargeTco(), chargeTco(), chargeTco(), chargeTco(), chargeTco(), chargeTco()];
return chargeUp
};
В массивах по 10 значений (считаем по порядку от 1 до 10) как реализовать с помощью jQuery так, чтоб при выборе Range во всех массивах сразу добавлялись и убирались значения? Для примера: При выборе Range = 6 получим код js
function negative() {
negativeUp = [ priceDifference(), 0, 0, 0, 0, 0 ];
return negativeUp
};
function positive() {
positiveUp = [ 0, tcoSavings(), tcoSavings(), tcoSavings(), tcoSavings(), tcoSavings() ];
return positiveUp
};
function ice() {
iceUp = [ analoguePlatform.onchange(), analogueTco(), analogueTco(), analogueTco(), analogueTco(), analogueTco()];
return iceUp
};
function charge() {
chargeUp = [ chargeTruckPrice(), chargeTco(), chargeTco(), chargeTco(),
chargeTco(), chargeTco()];
return chargeUp
};
Буду оооочень благодарен за помощь :thanks: |
nikto93i7,
мысли вслух ...
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<script>
function bindLate(a, b) {
return function() {
return a[b].apply(a, arguments)
}
}
var fn = {
num: 7
},
repeat = bindLate(fn, "repeat");
fn.repeat = function(a, b) {
for (var c = ["function" == typeof a ? a() : a], d = 0; d < this.num; d++) c.push("function" == typeof b ? b() : b);
return c
};
function tcoSavings()
{
return " * "
}
function priceDifference()
{
return " ! "
}
function negative() {
return repeat(priceDifference, 0)
};
function positive() {
return repeat(0, tcoSavings)
};
</script>
<body>
<input class="rangenain" id="term1" type="range" step=1 min="1" max="10" value="7" onchange="fn.num = this.value">
<input name="" type="button" value="test positive" onclick="alert(positive());">
<input name="" type="button" value="test negative" onclick="alert(negative());">
</body>
</html>
|
Спасибо Рони!)) ты снова меня спас!!)))
|
Буду разбираться с этим вариантом!)) А можно ли с помощью jQuery это реализовать?
|
nikto93i7,
а куда jQuery пихать? разве что заменить onchange на $(...).on('change', ....) |
Тоооочно!!!! Вот теперь я понял свою ошибку!!)))
|
| Часовой пояс GMT +3, время: 11:34. |