Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui Jquery UI滑块-为值指定名称_Jquery Ui_Slider_Names - Fatal编程技术网

Jquery ui Jquery UI滑块-为值指定名称

Jquery ui Jquery UI滑块-为值指定名称,jquery-ui,slider,names,Jquery Ui,Slider,Names,我需要为jQueryUI滑块的值指定名称——这可能吗 以下是迄今为止的代码: <script type="text/javascript"> $(function() { $("#slider_style").slider({ value:2, min: 1, max: 3, step: 1, slide: function(event, u

我需要为jQueryUI滑块的值指定名称——这可能吗

以下是迄今为止的代码:

<script type="text/javascript">
    $(function() {
        $("#slider_style").slider({
            value:2,
            min: 1,
            max: 3,
            step: 1,
            slide: function(event, ui) {
                $("#style_type").val( ui.value );
            }
        });
        $("#style_type").val( $("#slider_style").slider("value") ); 
    });
</script>

$(函数(){
$(“滑块样式”)。滑块({
价值:2,
民:1,,
最高:3,
步骤:1,
幻灯片:功能(事件、用户界面){
$(“#style_type”).val(ui.value);
}
});
$(“#style_type”).val($(“#slider_style”).slider(“value”);
});

基本上,我想让1作为单词PLAY出现在
#slider_style
div中,2作为单词HEAL,3作为RELAX–有人能指出这是如何实现的吗?

您可以使用查找对象来获取值:

var lookup = {
    1: 'PLAY',
    2: 'HEAL',
    3: 'RELAX'
}
然后在
幻灯片中
函数设置该对象的值:

...
slide: function(event, ui) {
    $('#style_type').val(lookup[ui.value]);
}

这将使
#style_type
根据滑块获得播放、治疗或放松值。这就是你的意思吗?

是的!!不过我有点笨——我该如何在代码中实现它呢?我知道要修改幻灯片:函数。但我通常在哪里添加查找对象?对了,它工作正常。。。有一个缺点。。。默认情况下,如何将值作为查找对象显示在#style_类型中?目前,它只显示为1,然后在移动滑块时按我的要求执行操作。代码现在是:-$(function(){var lookup={1:'PLAY',2:'HEAL',3:'RELAX'}$(“#slider_style”).slider({value:1,min:1,max:3,step:1,slide:function(event,ui){$('style#type').val(lookup[ui.value])}$(“#style#type”).val($($(“#slider style#style#style”).slider type”).slider value”);在
$(“#slider_style”).slider…
行之前,添加
$(“#style_type”).val(查找[2]),因为滑块中的默认值为2。如果它对你有帮助,不要忘记+1并将此答案设置为已接受。干杯!我移动了$('#style_type').val(lookup[2]);在行$(“#style_type”).val($(“#slider_style”).slider(“value”))的下方;这个很好用!