Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Замена значения в массиве (https://javascript.ru/forum/jquery/57743-zamena-znacheniya-v-massive.html)

nikto93i7 17.08.2015 21:53

Замена значения в массиве
 
Доброе время суток форумчане!!)))

Помогите пожалуйста разобраться с одной проблемой.. уже не один час потратил на вроде простую задачу :(

Есть 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:

рони 17.08.2015 22:53

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>

nikto93i7 17.08.2015 23:26

Спасибо Рони!)) ты снова меня спас!!)))

nikto93i7 17.08.2015 23:27

Буду разбираться с этим вариантом!)) А можно ли с помощью jQuery это реализовать?

рони 17.08.2015 23:34

nikto93i7,
а куда jQuery пихать?
разве что заменить onchange на $(...).on('change', ....)

nikto93i7 18.08.2015 01:04

Тоооочно!!!! Вот теперь я понял свою ошибку!!)))


Часовой пояс GMT +3, время: 12:12.