<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
? ? <title></title>
</head>
<body>
? ? <input type="text" id="test"/>
? ? <input type="button" value="test" id="btn_test" onclick="tt()" />
? ? <script>
? ? ? ? function tt() {
? ? ? ? ? ? var t = document.getElementById("test").value
? ? ? ? ? ? var patt1 = new RegExp(/\s+/g);
? ? ? ? ? ? if (patt1.test(t)) {
? ? ? ? ? ? ? ? alert("有空格");
? ? ? ? ? ? }
? ? ? ? ? ? alert(t.replace(/\s+/g, ""));
? ? ? ? }
? ? </script>
</body>
</html>