trim()方法,类似Python中的strip(),用去去除字符串对象前后的空格。
<!DOCTYPE html> <html> <body> <script> var s = " afsdf "; document.write("|" + s + "|" + "<br>"); var s2 = s.trim(); document.write("|" + s2 + "|" + "<br>"); </script> </body> </html>