Trimming whitespace from the END of a string only, with jQuery

前端 未结 2 653
故里飘歌
故里飘歌 2021-02-07 05:28

I know of the jQuery $.trim() function, but what I need is a way to trim whitespace from the END of a string only, and NOT the beginning too.

So

  str =\         


        
2条回答
  •  我在风中等你
    2021-02-07 06:34

    For some browsers you can use: str = str.trimRight(); or str = str.trimEnd();

    If you want total browser coverage, use regex.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd

提交回复
热议问题