给滑块赋值

时间:2013-11-26 12:54:32

标签: javascript jquery html slider

嗨,我必须说这不是我的代码..别人做了它,现在我很想弄清楚我怎么能给三个滑块赋值。 我不想要一个默认值,我希望每个滑块都可以从中获取:value =“@ getValueForThisSlider(o._1.getId)”,你可以在HTML中看到每个滑块都有不同的方法,我找不到任何解决方案显示正确的价值。请帮忙!谢谢!

JS:

$(".rating .slider").each(function () {
            $(this).empty().slider({
                range: "min",
                value: ??
                step: 0.1,
                min: 1,
                max: 10,
                slide: function (event, ui) {
                    $(this).parent().find(".amount").val(ui.value);
                }
            });
            $(this).parent().find(".amount").html($(this).slider("value"));
        });    

HTML:

<div class="field field-wrapper-rating" name="changes-values" id="change-values" style="display: none;">
  <div class="rating rating-price"> PriceQuality <span name="priceQuality" id="priceQuality" class="amount" value="@getPriceQuality(o._1.getId)"></span>
     <div id="slider-kwaliteit" class="slider" name="priceQuality"></div>
  </div>

  <div class="rating rating-hygiene"> Hygiene <span name="hygiene" id="hygiene" class="amount"></span>
   <div id="slider-hygiene" class="slider" name="hygiene"></div>
  </div>

  <div class="rating rating-service"> Service <span name="service" id="service" class="amount"></span>
    <div id="slider-service" class="slider" name="service" value="@getService(o._1.getId)"></div>
  </div>

1 个答案:

答案 0 :(得分:0)

看起来slider元素具有value属性,然后

$(".rating .slider").each(function () {
    var $this = $(this),
        $amount = $this.parent().find(".amount");
    $this.empty().slider({
        range: "min",
        value: $this.attr('value'),
        step: 0.1,
        min: 1,
        max: 10,
        slide: function (event, ui) {
            $amount.val(ui.value);
        }
    });
    $amount.html($this.slider("value"));
});

演示:Fiddle