JQuery Range输入监听器

嘿jquery和hmtl5范围有点麻烦。 我试着在改变时获取值,但事件监听器没有捕获它。 目前我的代码是:

HTML

html += '
  • Apply Credits: '+credits+'
  • '

    JS是:

     $('#discount_credits').mousewheel( function() { alert('it changed!'); alert('new value = ' + $(this).val()); }); 

    我也试过了

     $('#discount_credits').change( function() { alert('it changed!'); alert('new value = ' + $(this).val()); }); 

    似乎都没有用。 难道我做错了什么?

     $('input[type=range]').on('input', function () { $(this).trigger('change'); }); 

    这会在每个input事件上触发change事件。

    在使用change HTML5 上似乎没有任何问题。

    请参阅: http : //jsfiddle.net/DerekL/BaEar/33/

    我假设您的span有一个id: ...让我们假设您有一些滑块,并且如果有任何滑动,您希望看到文本更改:

     
  • Apply Credits1:
  • Apply Credits2:
  • 50

    试试这个:

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

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

    现在让我们假设您有一些滑块,但是如果移动了特定的滑块,您希望看到文本更改。 (我假设它是因为范围输入在li标签内,你给它起了一个名字):

     
  • Apply Credits1: 50
  • Apply Credits2: 50
  • 试试这个:

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

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

    on change事件似乎对我有用 : http : //jsfiddle.net/zV3xD/7/

      0 $('#discount_credits').change( function() { var newValue = this.value; $('#newValue').html(newValue); });​ 

    或者您可以尝试这样的事情:

     
    = 0

    使用此处的output示例: https : //developer.mozilla.org/en-US/docs/Web/HTML/Element/output