简体   繁体   中英

Turning slider numbers into abbreviations with jQuery

My slider code:

$(document).ready(function() {
  $("#slider").slider({
    min: 0,
    max: 1000000,
    step: 25000,
    range: true,
    values: [0, 1000000],
    slide: function(event, ui) {
      for (var i = 0; i < ui.values.length; ++i) {
        console.log(ui.values[i].split("").length); // ERROR HERE
        $("span.sliderValue[data-index=" + i + "]").text(ui.values[i]);
      }
    }
  });
});

However, I get the error:

Uncaught TypeError: ui.values[i].split is not a function

For now, I want to get the length of the string.

How do I fix this?

Seems like you are trying to get the 'length' property out of a number instead of a string. You should first convert it to string and then get the length like:

ui.values[i].toString().length

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM