<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>去除字符串左右两边的空格</title>
</head>
<body>
	<h2>测试去除字符串左右两边的空格</h2>
	<input type="text"  >
	<input type="button"  >
</body>
<script type="text/javascript">
	window.onload = function() {
		var _btn = document.getElementById('btn');
		   _strs = document.getElementById('strs');

		_btn.onclick = function() {
			_strs.value = _strs.value.replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, "");   //ASCII 160 空格, 全角空格 16进制ASCII编码
		};
	};
</script>
</html>

相关文章:

  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2022-01-22
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
猜你喜欢
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2021-08-04
  • 2022-12-23
相关资源
相似解决方案