它必须是一个小问题,但我找不到它。也许你们中的一个可以在这里帮助我。
Javascript
function white_space(field)
{
field.value = field.value.replace(/^\s+/, "");
}
function validate(){
var formname=document.reg_form;
var fname=formname.fname.value;
var mess="";
var uname=formname.prodName.value;
if(uname==""){
mess= mess+"User Name cannot be blank\n";
}
var pass=formname.prodPrice.value;
if(pass==""){
mess= mess+"Password cannot be blank\n";
}
if(mess){
alert(mess);
return false;
}
}
HTML 表格
<form class="form-signin" action="#" onSubmit="return validate();" name="reg_form">
<h2 class="form-signin-heading">Sign-In</h2>
<input type="text" class="input-block-level" name="prodName" placeholder="Email address" onKeyPress="white_space(this)">
<input type="password" class="input-block-level" name="prodPrice" placeholder="Password" onKeyPress="white_space(this)">
<label class="checkbox">
<input type="checkbox" value="remember-me"> Remember me
</label>
<button class="btn btn-large btn-primary" type="submit">Sign in</button>
</form>
错误
浏览器不显示空字符串错误。