<
html
>
< head ></ head >
<!-- 文本输入,不能不为空不能有空格 -->
< script > ...
function chk(f)
...{
var id=f.id.value;
if(id=="")
...{
alert("id不能为空!");
f.id.focus();
return false;
}
if(id.charAt(0)==" "||id.charAt(id.length-1)==" ")
...{
alert("id前面或者后面不能有空格!");
f.id.focus();
return false;
}
}
</ script >
< body >
< form name ="form1" method ="post" action = "#" onsubmit ="return chk(this)" >
< input name ="id" type ="text" />
< input type =submit name =button value ="提交" />
</ form >
<!-- 复选框不至少选择一项 -->
< SCRIPT LANGUAGE ="JavaScript" > ...
function check()
...{
var f=document.getElementById("form1");
var obj=document.getElementsByName("aa");
for(var i=0;i<obj.length;i++)
...{
if(obj[i].checked==true)
...{
var flag="ok";
break;
}
}
if(flag != "ok")
...{
alert("至少选择一项");
return false;
}
else
...{
f.submit();
}
}
</ SCRIPT >
< form id ="form1" action ="#" >
< input type =checkbox name ="aa" value ="a" > a
< input type =checkbox name ="aa" value ="b" > b
< input type =checkbox name ="aa" value ="c" > c
< br >
< input type ="button" onclick ="check()" value ="提交" >
</ form > </ body >
</ html >
< head ></ head >
<!-- 文本输入,不能不为空不能有空格 -->
< script > ...
function chk(f)
...{
var id=f.id.value;
if(id=="")
...{
alert("id不能为空!");
f.id.focus();
return false;
}
if(id.charAt(0)==" "||id.charAt(id.length-1)==" ")
...{
alert("id前面或者后面不能有空格!");
f.id.focus();
return false;
}
}
</ script >
< body >
< form name ="form1" method ="post" action = "#" onsubmit ="return chk(this)" >
< input name ="id" type ="text" />
< input type =submit name =button value ="提交" />
</ form >
<!-- 复选框不至少选择一项 -->
< SCRIPT LANGUAGE ="JavaScript" > ...
function check()
...{
var f=document.getElementById("form1");
var obj=document.getElementsByName("aa");
for(var i=0;i<obj.length;i++)
...{
if(obj[i].checked==true)
...{
var flag="ok";
break;
}
}
if(flag != "ok")
...{
alert("至少选择一项");
return false;
}
else
...{
f.submit();
}
}
</ SCRIPT >
< form id ="form1" action ="#" >
< input type =checkbox name ="aa" value ="a" > a
< input type =checkbox name ="aa" value ="b" > b
< input type =checkbox name ="aa" value ="c" > c
< br >
< input type ="button" onclick ="check()" value ="提交" >
</ form > </ body >
</ html >
<!-- 文本框内不能输入文字 -->
<input type="text" value="" name="test" onKeyUp="this.value=this.value.replace(/[^/x00-/xff]/g,'');">