function trim(strValue)
{
if(strValue == null || strValue.length == 0) {
return ("");
} var i = 0; while(strValue.charAt(i) == "") {
i++;
} return (strValue.substring(i));
}
//——————————————————————————〉
if(trim(***) == ""){
alert("");
}
{
if(strValue == null || strValue.length == 0) {
return ("");
} var i = 0; while(strValue.charAt(i) == "") {
i++;
} return (strValue.substring(i));
}
//——————————————————————————〉
if(trim(***) == ""){
alert("");
}
<!--
function check(theForm)
{
if (theForm.username.value=="")
{
alert("请填写用户名!");
theForm.username.focus();
return(false);
}
if (theForm.password.value=="")
{
alert("请填写密码!");
theForm.password.focus();
return(false);
}
}
-->
</script>然后在Form中加入:
<form onSubmit="return check(this)">
function CheckForm()
{
for(iIndex=0;iIndex<document.forms[0].elements.length;iIndex++)
{
if(document.forms[0].item(iIndex).tagName=="INPUT")
{
if(document.forms[0].item(iIndex).type=="text")
{
if(document.forms[0].item(iIndex).value=="")
{
return false;
}
}
}
}
return true;
}
</script>
<form>
<input type=text id="T1" value="">
<input type=text id="T2" value="">
<input type=text id="T3" value="">
<br>
<input type=button id="B1" value="效验" onclick="if(!CheckForm()){window.confirm('存在NULL')}">
</form>
String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g,"");}
</script><input onblur="if(value.trim()==''){alert('不可填空!'); focus()}">