改一下吧:
function checkform(){
if (document.myform.username.value==''|| document.myform.password.value==''){
alert("打 * 处不能为空!");
document.getElementById('dd').blur();
return false;}
return true;
}
<form name="myform" method="post" action="...." onsubmit="return checkform()">
<input type="text" name="username" size="10" id="username" >
<input type="text" name="password" id="password" >
<input type="submit" name="enter" id="dd" value='submit'>
</form>
function checkform(){
if (document.myform.username.value==''|| document.myform.password.value==''){
alert("打 * 处不能为空!");
document.getElementById('dd').blur();
return false;}
return true;
}
<form name="myform" method="post" action="...." onsubmit="return checkform()">
<input type="text" name="username" size="10" id="username" >
<input type="text" name="password" id="password" >
<input type="submit" name="enter" id="dd" value='submit'>
</form>
function checkfrm()
{
var frm = document.forms.myform;
if(frm.username.value == "")
{
alert("请输入用户名!");
frm.username.focus();
return false;
}
if(frm.password.value == "")
{
alert("请输入密码!");
frm.password.focus();
return false;
}
return true;
}
</SCRIPT>
<form name="myform" method="post" action="...." onsubmit="return checkfrm();">
<input type="text" name="username" size="10">
<input type="text" name="password">
<input type="submit" name="enter" id="dd" value='submit'>
</form>
if (document.myform.username.value==''|| document.myform.password.value==''){
alert("打 * 处不能为空!");
document.getElementById('dd').blur();
event.returnValue=false;}
}function check(){
if(event.keyCode==13&&document.myform.username.value==''){
event.returnValue=false;
}}