在项目中使用jquery库 经常会用到trim方法 ,用来去除空格
在firefox 下可以运行 ,但在IE下却抱错,后来一检查主要是写法不对。
语法:jQuery.trim( str )
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.
错误写法:
<p>
</p>
此写法在firefox下可以运行,在IE下报错。
正确写法:
var value = $.trim($(this).val());
此记录用于自省。
解决jQuery trim方法在IE浏览器下报错的问题
本文详细阐述了在项目中使用jQuery库时遇到trim方法在IE浏览器下无法正常运行的问题,并提供了正确的写法解决方案。通过对比错误与正确写法,帮助开发者避免类似错误,确保代码在不同浏览器环境下的一致性。
2234

被折叠的 条评论
为什么被折叠?



