Jquery Mobile Slider change event

后端 未结 10 1901
独厮守ぢ
独厮守ぢ 2021-01-02 11:14

I have a jquery mobile slider on a simple page. When I drag the slider, the value updates as expected in the textbox. I have looked but cannot find where this logic is happe

10条回答
  •  遥遥无期
    2021-01-02 11:43

    The problem with your code is that the javascript binding the event of change to the elements is evaluated before they were actually created in the html, thus no element get binded to the change event as you specified.

    Try this:

    $('#slider-1').live('change', function(){
      doYourStuffHere();
    });
    

    Briefly, live means that JQuery will keep on binding events to elements matching the specified selector even if they were not present at time of evaluating the JS for binding, so this code will bind all present and future html elements which match #slider-1 selector with the proper change callback.

    Another alternative is to use JQuery 'on' binding which acts little bit differently, but can still do the job. Have a look at the documentation for 'on' here.

提交回复
热议问题