<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>test js</title>
<script>
function trim (str) {
// 用正则表达式将前后空格
// 用空字符串替代。
return str.replace(/(^\s*)|(\s*$)/g, "");
}
function doSubmit() {
var temp = document.getElementsByTagName("input");
for (i=0;i<temp.length;i++){
if (temp[i].type=="text" && temp[i].value && trim(temp[i].value).length !=0 ){
temp[i].value = trim(temp[i].value);
}
}
}
</script>
</head>
<body>
<form action="" name="form1">
<input type="text" name="a">
<input type="text" name="b">
<input type="button" name="submit" οnclick="doSubmit();" value="提交">
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>test js</title>
<script>
function trim (str) {
// 用正则表达式将前后空格
// 用空字符串替代。
return str.replace(/(^\s*)|(\s*$)/g, "");
}
function doSubmit() {
var temp = document.getElementsByTagName("input");
for (i=0;i<temp.length;i++){
if (temp[i].type=="text" && temp[i].value && trim(temp[i].value).length !=0 ){
temp[i].value = trim(temp[i].value);
}
}
}
</script>
</head>
<body>
<form action="" name="form1">
<input type="text" name="a">
<input type="text" name="b">
<input type="button" name="submit" οnclick="doSubmit();" value="提交">
</form>
</body>
</html>