代码示例:(标识:eg_js_string_trim)
<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String.trim()</h1>

<p>点击这个按钮来输出已删除空白字符的字符串。</p>

<button onclick="myFunction()">试一试</button>

<p><strong>注释:</strong>Internet Explorer 8 或更低版本不支持 trim() 方法。</p>

<script>
function myFunction() {
  var str = "     Hello World!     ";
  alert(str.trim());
}
</script>

</body>
</html>
运行结果: