如何使用jquery更改input type=range的输入值、最小值和最大值?

7

我对jquery和html5不太熟悉。

我的jquery代码是:

var A_Route=['A1','A2','A3',.....'A50'];
var counter=0;
$("input[name='radio-choice']").change(function(){
    if ($(this).val() == "on")
    {
        $('#slider').val(A_Route[counter]);

    }

当我选择值为ON的单选按钮时,滑块的最小和最大值应自动变为A1和A50。当我滑动滑块时,值应从A1到A50进行更改。
我的HTML如下:
<div data-role="fieldcontain">
                <fieldset data-role="controlgroup" data-type="horizontal">
                    <legend>Layout view:</legend>
                          <input type="radio" name="radio-choice" id="radio-choice-c" value="on" checked="checked" />
                          <label for="radio-choice-c">List</label>
                          <input type="radio" name="radio-choice" id="radio-choice-d" value="off" />
                          <label for="radio-choice-d">Grid</label>
                          <input type="radio" name="radio-choice" id="radio-choice-e" value="other" />
                          <label for="radio-choice-e">Gallery</label>
                            </fieldset>
           </div>

<div data-role="fieldcontain">
        <label for="slider">Room:</label>
        <input type="range" name="slider" id="slider" value="--------" min=? max=? data-highlight="true"  />
</div>

您认为最小和最大代码应该是什么?如何将输入值从A1更改为A50?

1个回答

9
输入滑块的值应该只是一个有效的浮点数。所以,我认为它不能与您想要使用的最小最大值配合使用。
关于设置最小值和最大值属性的jQuery代码,您应该使用属性方法:attribute
    $('#slider').attr('min', A_Route[0]);
    $('#slider').attr('max', A_Route[3]);

点击这里查看它的运行效果。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接