<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script>
function checkSpace() {
var obj = document.getElementById("name");
var str = obj.value;
if (str.indexOf(" ") >=0) alert("输入有空格!");
obj.value = str.replace(/\s/g, ""); // 这句话可以强制删除所有空格
}
</script>
</head>
<body>
<input id="name" type="text" value="">
<input type="button" value="提交" onclick="checkSpace()">
</body>
</html>