可以的
<script>
function f1()
{
if(document.theform.pswc.value!=document.theform.psw.value )
{
//alert(document.theform.pswc.value);
document.theform.pswc.focus();
return false;
}
else
{
return true;
}
}
</script>
<form name="theform">
<input type="text" id="pswc" name="pswc">
<br>
<input type="text" id=psw name="psw">
<input type="button" onclick=alert(f1())>
</form>
<script>
function f1()
{
if(document.theform.pswc.value!=document.theform.psw.value )
{
//alert(document.theform.pswc.value);
document.theform.pswc.focus();
return false;
}
else
{
return true;
}
}
</script>
<form name="theform">
<input type="text" id="pswc" name="pswc">
<br>
<input type="text" id=psw name="psw">
<input type="button" onclick=alert(f1())>
</form>
var a =document.theform.pswc.value;
var b =document.theform.psw.value;
if(a!=b){
alert("error");
document.theform.psw.focus();
return false;
}
这样我也试过呀,不行啊?
但是我表单已经加过一个了方法了
<SCRIPT language="JavaScript">
function mycheck(){
if(document.theform.username.value==""){
alert("请输入用户名!");
document.theform.username.focus();
return false;
}
if(document.theform.psw.value==""){
alert("请输入密码");
document.theform.psw.focus();
return false;
}
if(document.theform.pswc.value==""){
alert("请再次输入密码");
document.theform.pswc.focus();
return false;
}
if(document.theform.e_mail.value==""){
alert("请输入E-mail");
document.theform.e_mail.focus();
return false;
}
if(document.theform.pswc.value!=document.theform.psw.value ){
alert(document.theform.pswc.value);
document.theform.pswc.focus();
return false;
}}
</SCRIPT>
<form action="reghandle.jsp" method="post" name="theform" onSubmit="return mycheck()">