在项目中使用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.

错误写法:

 var value = $(this).val().trim();

此写法在firefox下可以运行,在IE下报错。

正确写法:

var value = $.trim($(this).val());

此记录用于自省。

posted on 2012-09-05 15:40  justincai  阅读(604)  评论(0编辑  收藏  举报