jquery.trim compared to string.trim
问题 Is there any difference between jQuery trim and native JavaScript one? Is there any other behaviour, safety, performance? 回答1: JavaScript .trim() was defined in ES 5.1, and will not work for IE<9 . Therefore, if you already use jQuery you could use the less performant $.trim() jQuery's $.trim() Method does: trim: function( text ) { return text == null ? "" : ( text + "" ).replace( rtrim, "" ); } where rtrim is basically this RegExp new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)"