小白教程
所有教程
关于
Search
172.69.58.214
172.69.58.214
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Misc trim”的源代码
本页内容
上一节:
Misc_parsexml
下一节:
Misc_type
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:$.trim()}}[[Category:jquery ref misc|35]] = jQuery.trim()方法 = [[jquery ref misc|jQuery 杂项方法]] 删除字符串开始和末尾的空格 <sample title="" desc="" lang="html" hererun="1"> $(function () { var str = " lots of spaces before and after "; $( "#original" ).html( "Original String: '" + str + "'" ); $( "#trimmed" ).html( "$.trim()'ed: '" + $.trim(str) + "'" ); }) </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script> </head> <body> <pre id="original"></pre> <pre id="trimmed"></pre> <script> $(function () { var str = " lots of spaces before and after "; $( "#original" ).html( "Original String: '" + str + "'" ); $( "#trimmed" ).html( "$.trim()'ed: '" + $.trim(str) + "'" ); }) </script> </body> </html> </run> == 定义和用法 == $.trim() 函数用于去除字符串两端的空白字符。 $.trim() 函数将在 jQuery 3.5 及以上版本废弃,可以使用 JavaScript 原生的 [[jsref trim|String.prototype.trim]] 代替。 '''注意:'''$.trim()函数会移除字符串开始和末尾处的所有换行符,空格(包括连续的空格)和制表符。如果这些空白字符在字符串中间时,它们将被保留,不会被移除。 == 语法 == $.trim( str ) {| class="table table-striped table-hover" ! 参数 ! 描述 |- | str | String类型 需要去除两端空白字符的字符串。 |} [[jquery ref misc|jQuery 杂项方法]]
返回至“
Misc trim
”。
上一节:
Misc_parsexml
下一节:
Misc_type