如何从jQuery UI滑块获取价值?

时间:2022-09-10 14:08:31

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?

我正在研究http://gamercity.info/ymusic/。我正在使用UI滑块作为搜索栏。播放视频时,如果用户点击搜索栏上的任何位置,我想调用seekTo(秒)功能。点击事件后如何获得秒的新值?

8 个解决方案

#1


65  

To read slider value/percentage value at anytime:

要随时读取滑块值/百分比值:

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

#2


23  

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

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

#3


12  

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

#4


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/

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

you can have a function like this

你可以拥有这样的功能

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

#5


5  

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

使用jQuery v2.1.1和jQuery-ui v1.12.1进行测试

#6


0  

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);        }    });});

#7


0  

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:

下面的示例将向您展示如何获取输入字段中的更改值以保存在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="">

#8


0  

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

#1


65  

To read slider value/percentage value at anytime:

要随时读取滑块值/百分比值:

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

#2


23  

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

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

#3


12  

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

#4


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/

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

you can have a function like this

你可以拥有这样的功能

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

#5


5  

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

使用jQuery v2.1.1和jQuery-ui v1.12.1进行测试

#6


0  

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);        }    });});

#7


0  

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:

下面的示例将向您展示如何获取输入字段中的更改值以保存在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="">

#8


0  

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