JQuery Range Input Listener

后端 未结 5 846
-上瘾入骨i
-上瘾入骨i 2021-02-05 03:45

Hey having a little trouble jquery and the hmtl5 range. I\'m try to get the values as they changed but the event listener is not capturing it. Currently my code is:

HTML

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 04:22

    I assume your span has an id: ... Lets also assume that you have a few sliders, and you want to see a text change if any of them were moved:

  • Apply Credits1:
  • Apply Credits2:
  • 50

    Try this:

    $(document).ready(function(){
      $("[type=range]").change(function(){
        var newval=$(this).val();
        $("#slidernumber").text(newval);
      });
    });
    

    http://jsfiddle.net/MahshidZeinaly/CgQ5c/

    Now lets assume that you have a few sliders, but you want to see a text change if a particular one of them were moved. (I assume it because the range input is inside li tag, and you gave it a name):

  • Apply Credits1: 50
  • Apply Credits2: 50
  • Try this:

    $(document).ready(function(){
      $("[type=range]").change(function(){
        var newv=$(this).val();
        $(this).next().text(newv);
      });
    });
    

    http://jsfiddle.net/MahshidZeinaly/2pe7P/1/

提交回复
热议问题