【问题标题】:Instantly Update Range Value with jQuery使用 jQuery 即时更新范围值
【发布时间】:2014-09-03 21:46:33
【问题描述】:

我有一个范围,我想立即更新显示其数值的范围。我的代码有效,但仅在您停止按住左键时才显示数值。

这是我所拥有的:

$("#length").change(function(){  // when range is altered, execute function
    len = $("#length").val(); // set variable "len" to the numeral value of range
    $("#password-length").html(len); // set "len" (numeral value) to a span
});

Fiddle.

【问题讨论】:

    标签: jquery html input range


    【解决方案1】:

    您可以同时检查 inputchange 事件来实现此目的。

    在这种情况下:

    $("#length").on('input change', function(){
       $("#password-length").html(this.value);
    });
    

    jsFiddle here

    【讨论】:

      【解决方案2】:

      也可以改为mousemove

      $("#length").mousemove(function(){
              len = $("#length").val();
          $("#password-length").html(len);
      });
      

      【讨论】:

      • 谢谢,但@null 的方法效果更好,因为它可以使用箭头。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-05
      相关资源
      最近更新 更多