Passing Slider Value to Other Functions

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 20:12:49

问题


I posted a similar question a few days ago and have done a bit more research and coding, and now I'm at a wall. I'm a complete newbie and needing more help.

I currently have one slider and two charts successfully rendering on the same page. I'd like to pass the value of the slider into the two chart functions such that as the slider is moved, the charts refresh. The slider is generated using the jQuery UI function. The charts are generated by the Highcharts function.

There is a "Method" in the jQuery Slider API called "value()" that will retrieve the value of the slider, as follows:

var selection = $( ".selector" ).slider( "value" );

Currently, the values for the charts are hard coded as numbers within the function code for the charts. I'd like to dynamically update the values for the charts based on the value of the slider.

Ideas?

Thanks,

Chris


回答1:


you could use the change function in the jquery UI documentation

$(function() {

    $("#slider").slider({
     change: function (event,ui){
      // your code here
    }
});
});

this should work for every time there is a change in your slider


this is how your code should look like

 change: function(event,ui)
      {
        $( "selector" ).val( ui.value );
      }


来源:https://stackoverflow.com/questions/13781489/passing-slider-value-to-other-functions

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