How to remove extra white spaces using javascript or jquery?

后端 未结 4 2202
粉色の甜心
粉色の甜心 2021-02-05 04:16

I got HTML element contains this:

    
P6C245RO
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-05 04:42

    element.text().replace(/\s+/g, " ");
    

    This uses a regular expression (/.../) to search for one or more (+) whitespace characters (\s) throughout the element's text (g, the global modifier, which finds all matches rather than stopping after the first match) and replace each with one space (" ").

提交回复
热议问题