Javascript 范围滑块-滑块不工作时运行功能?
我在页面上使用允许用户选择值。然而,noUISlider的话,当一个人滑动时,我希望它运行一个基本上检查数字的函数,如果数字低于某个值,它将以div显示文本 问题是,该值记录在隐藏输入中,但显示文本的功能永远不起作用 以下是我的函数代码:Javascript 范围滑块-滑块不工作时运行功能?,javascript,jquery,nouislider,Javascript,Jquery,Nouislider,我在页面上使用允许用户选择值。然而,noUISlider的话,当一个人滑动时,我希望它运行一个基本上检查数字的函数,如果数字低于某个值,它将以div显示文本 问题是,该值记录在隐藏输入中,但显示文本的功能永远不起作用 以下是我的函数代码: var heightSlide = $('.height-noUI'); var onSlide = function(){ var slideHeight = "$('input[name=CAT_Custom_8]').val();" if
var heightSlide = $('.height-noUI');
var onSlide = function(){
var slideHeight = "$('input[name=CAT_Custom_8]').val();"
if(slideHeight <= 20){
$('.height-noUI-text').text('Short');
}else if(slideHeight <= 40){
$('.height-noUI-text').text('Short to Medium');
}else if(slideHeight <= 60){
$('.height-noUI-text').text('Medium');
}else if(slideHeight <= 80){
$('.height-noUI-text').text('Medium to Tall');
}else if(slideHeight <= 100){
$('.height-noUI-text').text('Tall');
}
};
heightSlide.on('slide', onSlide);
var heightSlide=$('.height noUI');
var onSlide=函数(){
var slideHeight=“$('input[name=CAT_Custom_8]”)val()
如果(幻灯片重量我解决了你的问题。请检查代码以了解
这是一个
$(函数(){
$(“.height noUI”).noUiSlider({
范围:[01100],
起点:0,
范围:{
“min”:[0],
“最大值”:[100]
},
步骤:20,
连接:“降低”,
序列化:{
下:[
美元链接({
目标:$(“输入[name=CAT\u Custom\u 8]”)
})
],
格式:{
小数:0
}
}
});
var heightSlide=$('.height noUI');
var onSlide=函数(){
var slideHeight=$('.noUi origin').position().left/$('.noUi origin').parent().width()*100;//这里是技巧。
如果(slideHeight谢谢你的帮助。问题:当输入显示20时,它应该显示为短到中。我如何修复它?它应该在JSFIDLE中工作。我现在测试了它。20=>Short我知道发生了什么。slideHeight
大约是20.00000153354664,因此比20大。我添加了Math。floor()
来解决这个问题。干得好,我很乐意帮助你。
$(function() {
$(".height-noUI").noUiSlider({
range: [0, 100],
start: 0,
range: {
'min': [0],
'max': [100]
},
step: 20,
connect: "lower",
serialization: {
lower: [
$.Link({
target: $("input[name=CAT_Custom_8]")
})
],
format: {
decimals: 0
}
}
});
var heightSlide = $('.height-noUI');
var onSlide = function(){
var slideHeight = $('.noUi-origin').position().left / $('.noUi-origin').parent().width() * 100; //Here is the trick.
if(slideHeight <= 20){
$('.height-noUI-text').text('Short');
}else if(slideHeight <= 40){
$('.height-noUI-text').text('Short to Medium');
}else if(slideHeight <= 60){
$('.height-noUI-text').text('Medium');
}else if(slideHeight <= 80){
$('.height-noUI-text').text('Medium to Tall');
}else if(slideHeight <= 100){
$('.height-noUI-text').text('Tall');
}
};
heightSlide.on('slide', onSlide);
});