朋友们,我想对滑块进行限制,当前不能低于开始且超过结束。或者开始不能再结束了......
这是我的javascript代码,
`$(document).ready(function(){ $( “#滑盖”)。滑块({ 动画:真的, 值:0, min:0, 最大值:10, 步骤1, slide:function(event,ui){ 更新(1,ui.value); //改变 } });
$("#slider2").slider({
animate: true,
value:0,
min: 0,
max: 10,
step: 1,
slide: function(event, ui) {
update(2,ui.value); //changed
}
});
$("#slider3").slider({
animate: true,
value:0,
min: 0,
max: 10,
step: 1,
slide: function(event, ui) {
update(3,ui.value); //changed
}
});
//Added, set initial value.
$("#start").val(0);
$("#current").val(0);
$("#end").val(0);
update();
});
//changed. now with parameter
function update(slider,val) {
//changed. Now, directly take value from ui.value. if not set (initial, will use current value.)
var $start = slider == 1?val:$("#start").val();
var $current = slider == 2?val:$("#current").val();
var $end = slider == 3?val:$("#end").val();
$( "#start" ).val($start);
$( "#current" ).val($current);
$( "#end" ).val($end);
$('#slider a').html('<label> '+$start+' </label>');
$('#slider3 a').html('<label> '+$end+' </label>');
$('#slider2 a').html('<label> '+$current+' </label>');
}`
我已将此部分添加到其中,但它无效。
$(document).ready(function() {
$("#slider").slider({
animate: true,
value:0,
min: 0,
max: 10,
step: 1,
slide: function(event, ui) {
update(1,ui.value); //changed
}
});
var min1 = $("#slider").min();
$("#slider2").slider({
animate: true,
value:0,
min: 0,
max: 10,
values: [min1, 5]
step: 1,
slide: function(event, ui) {
update(2,ui.value); //changed
}
});
$("#slider3").slider({
animate: true,
value:0,
min: 0,
max: 10,
step: 1,
slide: function(event, ui) {
update(3,ui.value); //changed
}
});
//Added, set initial value.
$("#start").val(0);
$("#current").val(0);
$("#end").val(0);
update();
});
//changed. now with parameter
function update(slider,val) {
//changed. Now, directly take value from ui.value. if not set (initial, will use current value.)
var $start = slider == 1?val:$("#start").val();
var $current = slider == 2?val:$("#current").val();
var $end = slider == 3?val:$("#end").val();
$( "#start" ).val($start);
$( "#current" ).val($current);
$( "#end" ).val($end);
$('#slider a').html('<label> '+$start+' </label>');
$('#slider3 a').html('<label> '+$end+' </label>');
$('#slider2 a').html('<label> '+$current+' </label>');
}
你能帮我做一下限制吗?
谢谢