jQuery.trim()

jQuery.trim( str ) Returns: String

Description: Remove the whitespace from the beginning and end of a string.

  • version added: 1.0jQuery.trim( str )

    strThe string to trim.

The $.trim() function removes all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of the supplied string. If these whitespace characters occur in the middle of the string, they are preserved.

Examples:

Example: Remove the two white spaces at the start and at the end of the string.
<!DOCTYPE html> 
<html> 
<head> 
  <script src="http://code.jquery.com/jquery-latest.js"></script> 
</head> 
<body> 
   
        <pre id="original"></pre> 
        <pre id="trimmed"></pre> 
       
<script> 
  var str = "         lots of spaces before and after         "; 
  $("#original").html("Original String: '" + str + "'"); 
  $("#trimmed").html("$.trim()'ed: '" + $.trim(str) + "'"); 
</script> 
 
</body> 
</html>
Example: Remove the two white spaces at the start and at the end of the string.
$.trim("    hello, how are you?    ");
Result:
"hello, how are you?"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值