4

I am referring to

http://www.filamentgroup.com/lab/update_jquery_ui_slider_from_a_select_element_now_with_aria_support

and having hard time retrieving the selected value on the slider. Initially I was having a dropdown which had an onchange event associated with it.. and worked like a charm by calling

 <select id="myselect" onchange="myfunction(this);" >

but now requirement changed to a slider

 $('select#myselect').selectToUISlider({sliderOptions: {stop: function(e,ui) {alert(this.val());}}});

it throws me this.val() is not a function.

I also tried to use

$('select#myselect').selectToUISlider({sliderOptions: {stop: function(e,ui) {alert(ui);}}});

but using the ui argument also I could not retrieve the selected value... it just returns me the selected index.

the dropdown looks lke this

<select name="myselect" id="myselect">
            <option value="20">txt1</option>
            <option value="30">txt2</option>
            <option value="40" selected="selected">txt3</option>
            <option value="50">txt4</option>
            <option value="60">txt5</option>
        </select>

It would be excellent if I could just be able to trigger the onchange event of the select box but looks like when using the slider, the value of the dropdown changes but it does not trigger the event.

Any help is really appreciated!

Thanks

4

2 回答 2

4

您正在进行的事件是 UI 滑块,而不是<select>...但<select>值已经更新,所以只需获取它,如下所示:

$('#myselect').selectToUISlider({
  sliderOptions: {
    stop: function(e,ui) {
      var currentValue = $('#myselect').val();
    }
  }
});
于 2010-11-14T20:27:55.267 回答
1

我只是偶然发现了同样的问题,如果滑块或选择下拉菜单发生更改,我需要获取新值,但是当我使用选择下拉菜单时,“停止”选项不起作用。所以我只是将sliderOptions 'change' 选项与一个函数一起使用。所以就像尼克的答案一样,但像这样:

$("select").selectToUISlider({
    // labels and tooltipSrc are selectToUISlider specific options
    labels: 0,
    tooltipSrc: "value",
    sliderOptions: {
        // swapped out stop for change here
        change: function(e,ui) {
            console.log($('select').val());
        }
      }
});
于 2012-05-23T04:01:47.810 回答