How to extract number from a string in javascript

前端 未结 9 695
清歌不尽
清歌不尽 2020-12-08 19:23

I have an element in javascript like follows:

 280ms

I want to extract 280 from the span element. How can I do it?

9条回答
  •  抹茶落季
    2020-12-08 20:13

    Will it always end in "ms"? You can do:

    var num = s.substring(0, s.length-2) 
    

    where s is the string in the span. To get this value, you can use text(), html(), or innerHTML on the span.

提交回复
热议问题