新手提问: 关于focus

initcsdn 2002-05-10 01:10:01
我写了一个界面,让用户输入名称和密码后,登录到下一个界面。
代码如下:
<form name = "frmIndex" action = "ecommerca.asp" method = "post">
<table align = "center">
<tr><td>用户名称</td><td><input type="text" name = "txtUserName" size = "12" maxlength = "10"></td></tr>
<tr><td>口令</td><td><input type = "password" name = "txtPassword" size = "12" maxlength = "10"></td></tr>
<tr><td><input type = "button" name = "btnOk" value = "登录" style = "Heigh:30px;Width:50px" onclick = "btnOk_onclick()"></td>
</tr>
</table>
</form>

在名称或密码为空时给出提示,光标能在名称或密码的文本框上,代码如下:

<Script Language = "JavaScript">
<!--
function btnOk_onclick()
{
var strUserName;
var strPassword;
strUserName = document.frmIndex.txtUserName.value;
strPassword = document.frmIndex.txtPassword.value;
if (strUserName.length == 0)
{
alert("请输入用户名称");
document.frmIndex.txtUserName.focus;
return false;
}
else if (strPassword.length == 0)
{
alert("请输入口令");
document.frmIndex.txtPassword.focus;
return false;
}
document.frmIndex.submit();
}

-->
</Script>

测试后,光标还是在button上,why?
...全文
31 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
MeXP 2002-05-10
  • 打赏
  • 举报
回复
改成这样应该没问题了,你试试
<form name = "frmIndex" action = "ecommerca.asp" method = "post" onsubmit="return btnOk_onclick();">
<table align = "center">
<tr><td>用户名称</td><td><input type="text" name = "txtUserName" size = "12" maxlength = "10"></td></tr>
<tr><td>口令</td><td><input type = "password" name = "txtPassword" size = "12" maxlength = "10"></td></tr>
<tr><td><input type = "submit" name = "btnOk" value = "登录" style = "Heigh:30px;Width:50px"></td></tr>
</table>
</form>


<Script Language = "JavaScript">
<!--
function btnOk_onclick()
{
var strUserName;
var strPassword;
strUserName = document.frmIndex.txtUserName.value;
strPassword = document.frmIndex.txtPassword.value;
if (strUserName.length == 0)
{
alert("请输入用户名称");
document.frmIndex.txtUserName.focus();
return false;
}
else if (strPassword.length == 0)
{
alert("请输入口令");
document.frmIndex.txtPassword.focus();
return false;
}
else
return true;
}

-->
</Script>
zheatg 2002-05-10
  • 打赏
  • 举报
回复
这样试试
<script language=javascript>
function CheckData(){
if(document.forma.txtUserName.value==''){
alert('请输入用户名称!');
document.forma.txtUserName.focus();
return false;
}
if(document.forma.txtPassword.value==''){
alert('请输入口令!');
document.forma.txtPassword.focus();
return false;
}

document.forma.action="submit.asp";
document.forma.submit();
}
</script>
leagenary 2002-05-10
  • 打赏
  • 举报
回复
focus-->focus()
在加个条件判断提交。
leagenary 2002-05-10
  • 打赏
  • 举报
回复
focus-->focus()
ChinaOk 2002-05-10
  • 打赏
  • 举报
回复
<form ... onsubmit="return btnok_onclick();">
0A....
<input type = "submit" name = "btnOk" value = "登录" style = "Heigh:30px;Width:50px" >
0A</form>
freezwy 2002-05-10
  • 打赏
  • 举报
回复
在你提交表单的时候,必须指定要检测的返回值。就是在form中指定return btnok_onclick()
wangfei2428 2002-05-10
  • 打赏
  • 举报
回复
<script language=vbcript>
sub btnOk_onclick()
if frmIndex.txtUserName.value=empty
msgbox "请输入用户名称"
frmIndex.elements(0).focus
else
if frmIndex.txtpassword.value=empty
msgbox "请输入口令"
frmIndex.elements(1).focus
else
frmIndex.submit
end if
end if
end sub
</script>
lovingkiss 2002-05-10
  • 打赏
  • 举报
回复
用MSE跟踪一下
popcode 2002-05-10
  • 打赏
  • 举报
回复
form这样改看看
<form name = "frmIndex" action = "ecommerca.asp" method = "post" onsubmit="return btnOk_onclick()">

<input type = "button" name = "btnOk" value = "登录" style = "Heigh:30px;Width:50px" >

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧