【问题标题】:jQuery Mobile Dual Range sliderjQuery Mobile 双范围滑块
【发布时间】:2012-02-12 07:45:23
【问题描述】:

我在 JQM 中制作了一个双范围滑块,将滑块放在彼此的顶部。有没有办法阻止最小值超过最大值?

我不确定滑块是否使用 HTML5 范围输入类型

<style type="text/css">
            .priceRangeInfo{
                position: relative;
                height: 30px;
                margin-top: 60px;
            }
            .priceRangeInfo label{
                position: absolute;
                top: -30px;
                left: 10px;
            }                            /* moves label field */
            .priceRangeInfo #buying_slider_min{
                top: -40px;
                position: absolute;
                left: 100px;
            }       /* moves first input field */ 
            .priceRangeInfo #buying_slider_max{
                top: -40px;
                position: absolute;
                left: 170px;
            }      /* move second input field */ 
            .priceRangeInfo div.ui-slider{
                position: absolute;
            }                   /* move both sliders - adressing 1st slider with CSS is hard */ 
            .priceRangeInfo div:last-child{
                position: absolute;
                left: 0px;
            }                 /* correct 2nd slider position to fit exactly on top of 1st slider */
        </style>
        <div class="priceRangeInfo">
              <label for="buying_slider_min">Price</label>
              <input type="range" name="buying_slider_min" id="buying_slider_min" class="minBuyingSlider" value="0" min="0" max="100" />
              <input type="range" name="buying_slider_max" id="buying_slider_max" class="maxBuyingSlider" value="100" min="0" max="100" />
        </div>

刚刚发现 YUI 有一个很棒的双滑块,可以与 JQM 完美配合!!!

http://developer.yahoo.com/yui/examples/slider/slider_dual_with_highlight.html

【问题讨论】:

  • 请使用您尝试过的示例代码和/或jsfiddle.net 编辑您的问题
  • 很抱歉,但不能放入 jsfiddle,因为它们需要包含一些图像。我已经在上面发布了一些代码
  • 您提到的 YUI 双滑块似乎不适用于我的 Android 手机。不确定这对于从事移动设备工作的任何人来说是一个可行的选择。

标签: jquery html jquery-mobile


【解决方案1】:

您必须这样创建滑块: html:

 <div id="slider-container-zucker" class="slider_style"></div>

和js:

 $(function () {

$('#slider-container-zucker').slider({
    range: true,
    min: 0,
    max: 9,
    values: 0, 9,
    change: function (event, ui) {
        $.ajax({
            type: "GET",
            url: url,
            success: function (result) {
                $("#Result").html(result);
            }
        });            

    }
});

});

有什么不清楚的可以问我

【讨论】:

    【解决方案2】:

    这样的工作是否可行:

    JS

    $('#buying_slider_min').change(function() {
        var min = $(this).val();
        var max = $('#buying_slider_max').val();
    
        if(min > max) {
            $('#buying_slider_max').val(min);
          $('.maxBuyingSlider').slider('refresh');  
        }
    });
    

    HTML

    <div class="priceRangeInfo">
          <label for="buying_slider_min">Price</label>
          <input type="range" name="buying_slider_min" id="buying_slider_min" class="minBuyingSlider" value="0" min="0" max="100" />
          <input type="range" name="buying_slider_max" id="buying_slider_max" class="maxBuyingSlider" value="100" min="0" max="100" data-track-theme="b"/>
    </div>
    

    CSS

    .priceRangeInfo{
        position: relative;
        height: 30px;
        margin-top: 60px;
    }
    .priceRangeInfo label{
        position: absolute;
        top: -30px;
        left: 10px;
    }                            /* moves label field */
    .priceRangeInfo #buying_slider_min{
        top: -40px;
        position: absolute;
        left: 100px;
    }       /* moves first input field */ 
    .priceRangeInfo #buying_slider_max{
        top: -40px;
        position: absolute;
        left: 170px;
    }      /* move second input field */ 
    .priceRangeInfo div.ui-slider{
        position: absolute;
    }                   /* move both sliders - adressing 1st slider with CSS is hard */ 
    .priceRangeInfo div:last-child{
        position: absolute;
        left: 0px;
    }
    

    【讨论】:

    • 您好,感谢您的帮助,但有没有办法让它不出错?我在 JQM 上尝试了 jQuery UI 和其他工具,但没有任何效果,因为 JQM 本身使用滑块()作为 javascript 的函数。有没有办法可以防止指针相互超过最小值或最大值?
    猜你喜欢
    • 1970-01-01
    • 2021-10-27
    • 2014-09-29
    • 1970-01-01
    • 1970-01-01
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    相关资源
    最近更新 更多