How to get value from jQuery UI slider?

拟墨画扇 提交于 2019-11-26 14:19:05

问题


I am working on http://gamercity.info/ymusic/. And I am using UI slider as seek bar. While the video is played I want to invoke a seekTo(seconds) function if user clicked anywhere on the seek bar. How to get new value of seconds after click event?


回答1:


To read slider value/percentage value at anytime:

var val = $('#slider').slider("option", "value");



回答2:


$('#slider').slider({
    change: function(event, ui) { 
        alert(ui.value); 
    } 
});​

http://jqueryui.com/demos/slider/




回答3:


var val = $("#slider").slider("value");



回答4:


I checked all the answers mentioned above, but found none useful as the following code:

$('#slider').slider("values")[0]; // for slider with single knob or lower value of range
$('#slider').slider("values")[1]; // for highest value of range

Tested with jQuery v2.1.1 and jQuery-ui v1.12.1




回答5:


$("#slider").slider(
{
            value:100,
            min: 0,
            max: 500,
            step: 50,
            slide: function( event, ui ) {
                $( "#slider-value" ).html( ui.value );
            }
}
);

JS FIDDLE EXAMPLE : http://jsfiddle.net/hiteshbhilai2010/5TTm4/1162/

you can have a function like this

function seekTo(seek_value)
{
$("#slider").slider('option', 'value',seek_value);

}



回答6:


  // Price Slider
        if ($('.price-slider').length > 0) {
            $('.price-slider').slider({
                min: 0,
                max: 2000,
                step: 10,
                value: [0, 2000],
                handle: "square",


            });
        }



$(document).ready(function(){

 $(".price-slider").on( "slide", function( event, ui ) {  console.log("LA RECTM");  var mm = $('.tooltip-inner').text(); console.log(mm);   var divide = mm.split(':');   console.log( "min:" +divide[0] + " max:" + divide[1] )     } );




})



回答7:


You can pass the value to any function or set any element with the value:

$(function () {
    $('#slider').slider({
        max: 100,
        slide: function (event, ui) {
            $('#anyDiv').val(ui.value);
        }
    });
});



回答8:


Late to the party but this question has still unanswered.

Below example will show you how to get value on change in an input field to save in DB:

$( "#slider-videoTransparency" ).slider({            
  value: "1",
  orientation: "horizontal",
  range: "min",
  max: 30,
  animate: true,
  change: function (e, ui) {

    var value = $(this).slider( "value" );
    $('.video_overlay_transparency').val(value);
  }  
});
<div id="slider-videoTransparency" class="slider-danger"></div>

<input type="hidden" name="video_overlay_transparency" class="video_overlay_transparency" value="">



回答9:


var value=document.getElementById('slider').value;
var a=value.split("specialName")//name=special charcter between minimum and maximum rang
var b=a[0];//this will get minimum range
var c=a[1];//this will get maximum range



回答10:


JQuery ui slider

var slider = $("#range_slider").slider({
    range: true,
    min: 0,
    max: 500,
    values: [0, 500],
    slide: function(event, ui) {
      var x = ui.values[0];
      var y = ui.values[1];
      $('#min').text( ui.values[0] )
      $('#max').text( ui.values[1] )
      $.ajax({
        url: '/search',
        type: 'GET',
        dataType: 'script',
        data: {min:x, max:y,term:food_item_name},
        success: function(repsonse){},
      });
    }
  });
});


来源:https://stackoverflow.com/questions/2939865/how-to-get-value-from-jquery-ui-slider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!