获取JQuery范围值

时间:2016-08-18 11:22:36

标签: javascript jquery html jquery-ui

我尝试在此值更改时检索JQuery的范围滑块值。 我试试这个:

HTML / PHP页面:

 <div class="total">
      <label for="">Total</label>
      <p><span class="monthrc"></span> Months</p>
    </div>

    <div class="month">
        <div class="input">
          <label for=""><span></span> Months</label>
          <input type="text" name="range" class="range min-1 max-12" value="6" id="month">
        </div>
    </div>

    <script type="text/javascript">
      $( "#month" ).slider({
        change: function( event, ui ) {}
      });
      $( "#month" ).on( "slidechange", function( event, ui ) {
        var slv = $("input[id=month]").val();
        $('.monthrc').append(slv);
      });
    </script>

JS页面:

options.slide = function(event, ui) {
      elem.find('label span').empty().append(ui.value);
      input.val(ui.value);
    };
    options.value = input.val();
    elem.find('label span').empty().append(input.val())

但它不起作用;(

Yazrihm, 谢谢你回答。

1 个答案:

答案 0 :(得分:0)

我希望我理解正确,因为你不是很准确。

$("#month").slider({
    range: "max",
    min: 1, // min value
    max: 12, // max value
    step: 1,
    value: 6, // default value of slider
    create: function(event, ui) {
        $(".monthrc").html(6); // default value of slider
    },
    slide: function(event, ui) {
        $(".monthrc").html(ui.value);
    }
});
<div class="total">
    <label for="">Total</label>
    <p><span class="monthrc"></span> Months</p>
</div>

<div id="month">
    <div class="input">
    </div>
</div>
 
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>