我上课了:
function Slider(name,orientation,range,disabled,min,max,value) {
this.name = name;
this.orientation = orientation;
this.range = range;
this.disabled = disabled;
this.min = min;
this.max = max;
this.value = value;
this.setSlider = function() {
jQ("#"+this.name).slider({
orientation: ''+this.orientation,
range: this.range,
disabled: this.disabled,
min: this.min,
max: this.max,
value: value,
change: function(event, ui) {
this.value = jQ("#"+name).slider("option", "value");
console.log(value);
sprawdzSume();
}
});
};
}
用于检查所有滑块的总和:
function sprawdzSume() {
var cena = 0;
if (slider3.value === 1) {
cena = slider1.value + slider2.value + slider3.value + 1 + slider4.value;
}
else{
cena = slider1.value + slider2.value + slider3.value + slider4.value;
};
if (cena > 7) {
jQ(function() {
jQ(slider5.name).slider({
value: 3
});
})
}
else if (cena > 5 && cena < 8) {
jQ(function() {
jQ(slider5.name).slider({
value: 2
});
})
}
else if (cena > 3 && cena < 6) {
jQ(function() {
jQ(slider5.name).slider({
value: 1
});
})
}
else {
jQ(function() {
jQ(slider5.name).slider({
value: 0
});
})
};
console.log(cena);
}
函数 sprawdzSume()更改最后第五个滑块的值。我想将滑块的值传递给此函数,然后使用该值执行一些操作。在这里,我创建了一些对象:
var slider1 = new Slider('slider1','vertical',false,false,0,1,1);
var slider2 = new Slider('slider2','vertical',false,false,0,3,3);
var slider3 = new Slider('slider3','vertical',false,false,0,1,1);
var slider4 = new Slider('slider4','vertical',false,false,0,3,3);
var slider5 = new Slider('slider5','vertical',false,true,0,3,3);
如何获取每个滑块的更改值,然后对它们执行某些操作?
答案 0 :(得分:0)
var selection = $(“#slider1”)。slider(“value”);