jQuery.trim()| jqueryAPI 2.2 中文手册- AspRain.cn 致力于Web开发技术翻译整理
From jQuery API 2.2.0
jQuery.trim()
分类:实用工具
返回: String
jQuery.trim( str )
描述:删除一个字符串开头和末尾的空白。
$.trim()函数会删除提供的字符串的开头和结尾处的新行符号、空白(包括不换行空白)以及制表符。如果空白字符出现在字符串的中间,它们会被保留下来。
示例
删除字符串开头和结尾处的空白。
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery.trim demo</title> <script src="https://code.jquery.com/jquery-1.10.2.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>
演示结果
删除字符串开头和结尾处的空白。
$.trim(" hello, how are you? ");
演示结果
"hello, how are you?"
如果网页上不能运行示例,请点击http://www.asprain.cn/jQueryAPI/jquery.trim.htm查看示例。
如果你觉得本文档对你有用,欢迎给翻译作者支付宝打赏,支持翻译作者源源不断翻译更多有用的技术文档。