标题:登录首页 弹框提示 写了没出效果,请问怎么改,谢谢
只看楼主
sunpei
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-11-28
 问题点数:0 回复次数:8 
登录首页 弹框提示 写了没出效果,请问怎么改,谢谢
要提示用户名或密码不能为空,请问要怎么改
我这写了但没出效果



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>
<form action=".jsp" method="post"onsubmit="return checkform()"name="form1">
<HEAD>

<TITLE>无标题页</TITLE>

<META http-equiv=Content-Type content="text/html; charset=gbk">

<LINK

href="images/public.css" type=text/css rel=stylesheet>

<LINK

href="images/login.css" type=text/css rel=stylesheet>

<STYLE type=text/css>

</STYLE>
<script language="javascript">
function checkform()
{
if(form11.username.value==""){
alert("用户名不能为空。");
form1.username.focus();
return false;
}
if(form1.username.value.length<1‖form1.username.value.length>20){
alert("用户名超出了范围(1~20).");
form1.username.focus();
return false;
}
if(form1.password.value==""){
alertt("密码不能为空。");
form1.password.focus();
return false;
}
if(form1.password.value.length<1‖form1.password.value.length>20){
alert("密码超出了范围(1~20).");
form1.password.focus();
return false;
}
}
</script>
<META content="MSHTML 6.00.2900.5848" name=GENERATOR>

</HEAD>

<BODY>

<DIV id=div1>

  <TABLE id=login height="100%" cellSpacing=0 cellPadding=0 width=800

align=center>

    <TBODY>

      <TR id=main>

        <TD>

          <TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%">

            <TBODY>

              <TR>

                <TD colSpan=4>&nbsp;</TD>

              </TR>

              <TR height=30>

                <TD width=380>&nbsp;</TD>

                <TD>&nbsp;</TD>

                <TD>&nbsp;</TD>

                <TD>&nbsp;</TD>

              </TR>

              <TR height=40>

                <TD rowSpan=4>&nbsp;</TD>

                <TD>用户名:</TD>

                <TD>

                  <INPUT class=textbox id=username name=username>

                </TD>

                <TD width=120>&nbsp;</TD>

              </TR>

              <TR height=40>

                <TD>密 码:</TD>

                <TD>

                  <INPUT class=textbox id=password type=password

            name=password>

                </TD>

                <TD width=120>&nbsp;</TD>

              </TR>

              <TR height=40>

                <TD><br></TD>

                <TD vAlign=center colSpan=2><br></TD>

              </TR>

              <TR height=40>

                <TD></TD>

                <TD align=right>

                  <INPUT id=btnLogin type=submit value=" 登 录 " name=btnLogin onclick="javascript:return(checkform());">

                </TD>

                <TD width=120>&nbsp;</TD>

              </TR>

              <TR height=110>

                <TD colSpan=4>&nbsp;</TD>

              </TR>

            </TBODY>

          </TABLE>

        </TD>

      </TR>

      <TR id=root height=104>

        <TD>&nbsp;</TD>

      </TR>

    </TBODY>

  </TABLE>

</DIV>

<DIV id=div2 style="DISPLAY: none"></DIV>

</CONTENTTEMPLATE>
</form>
</BODY>

</HTML>
搜索更多相关主题的帖子: return 用户名 PUBLIC content 密码 
2011-12-08 10:24
sunpei
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-11-28
得分:0 
不弹框的也可以,有些直接在输入用户名和密码的框后面,输出“用户名和密码不能为空”的文字
2011-12-08 10:26
xmlz
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:5
帖 子:294
专家分:1392
注 册:2010-8-29
得分:0 
没有发现form的开始标签
<form id="form1" ...>

脚本:
var form1=document.getElementById("form1");
if(form11.username.value==""){
alert("用户名不能为空。");
...
2011-12-08 11:35
sunpei
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-11-28
得分:0 
我改了成这样行了


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<TITLE>无标题页</TITLE>

<META http-equiv=Content-Type content="text/html; charset=gbk">

<LINK

href="images/public.css" type=text/css rel=stylesheet>

<LINK

href="images/login.css" type=text/css rel=stylesheet>

<STYLE type=text/css>

</STYLE>

<script>
function checkform(){
var form1 = document.form1;
if(form1.username.value.length<1 || form1.username.value.length>20){
alert("用户名超出了范围(1~20).");
form1.username.focus();
return false;
}
if(form1.password.value.length<1 || form1.password.value.length>20){
alert("密码超出了范围(1~20).");
form1.password.focus();
return false;
}
}
</script>
<META content="MSHTML 6.00.2900.5848" name=GENERATOR>

</HEAD>

<BODY>
<form name="form1" id="form1"action="check.jsp">
<DIV id=div1>

  <TABLE id=login height="100%" cellSpacing=0 cellPadding=0 width=800

align=center>

    <TBODY>

      <TR id=main>

        <TD>

          <TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%">

            <TBODY>

              <TR>

                <TD colSpan=4> </TD>

              </TR>

              <TR height=30>

                <TD width=380> </TD>

                <TD> </TD>

                <TD> </TD>

                <TD> </TD>

              </TR>

              <TR height=40>

                <TD rowSpan=4> </TD>

                <TD>用户名:</TD>

                <TD>

                  <INPUT class=textbox id=username name=username>

                </TD>

                <TD width=120> </TD>

              </TR>

              <TR height=40>

                <TD>密 码:</TD>

                <TD>

                  <INPUT class=textbox id=password type=password

            name=password>

                </TD>

                <TD width=120> </TD>

              </TR>

              <TR height=40>

                <TD><br></TD>

                <TD vAlign=center colSpan=2><br></TD>

              </TR>

              <TR height=40>

                <TD></TD>

                <TD align=right>

                  <INPUT id=btnLogin type=submit value=" 登 录 " name=btnLogin onclick="return checkform()">

                </TD>

                <TD width=120> </TD>

              </TR>

              <TR height=110>

                <TD colSpan=4> </TD>

              </TR>

            </TBODY>

          </TABLE>

        </TD>

      </TR>

      <TR id=root height=104>

        <TD> </TD>

      </TR>

    </TBODY>

  </TABLE>

</DIV>

<DIV id=div2 style="DISPLAY: none"></DIV>

</CONTENTTEMPLATE>
</form>
</BODY>

</HTML>
2011-12-08 20:42
JeffLi
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:116
注 册:2011-11-18
得分:0 
onclick="javascript:return(checkform());"

这里有问题 要改成
onclick="javascript:return checkform();"

我的企鹅:67567840
2011-12-09 14:14
jfei
Rank: 4
来 自:郑州
等 级:业余侠客
帖 子:92
专家分:268
注 册:2011-8-27
得分:0 
function checkform(){
var form1 = document.form1;
if(document.form1.username.value.length<1 ||document.form1.username.value.length>20){
alert("用户名超出了范围(1~20).");
document.form1.username.focus();
return false;
}
if(document.form1.password.value.length<1 ||document. form1.password.value.length>20){
alert("密码超出了范围(1~20).");
document.form1.password.focus();
return false;
}
}

虾米们!!!有意者加QQ 2434202652,2632939128联系我
2011-12-10 11:26
piaoxue
Rank: 3Rank: 3
来 自:地球
等 级:论坛游侠
威 望:3
帖 子:606
专家分:113
注 册:2005-9-19
得分:0 
if(form11.username.value==""){
alert("用户名不能为空。");
form1.username.focus();

我也没有发现你有from提交呀?

我是做平面设计、网站制作、网站推广、主机域名等业务的站长。有需要的给我站内信吧。
2011-12-21 15:06
fengzhijian
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-12-22
得分:0 
何不这样写  将form表达上面的onsubmit事件改成onclick时间;当验证通过后;通过document.getElementById("fromId").submit();这样提交就不会有错了。
2011-12-22 15:29
smallmoon521
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:517
专家分:1373
注 册:2008-4-21
得分:0 
建议用Firefox,安装FireBug插件,调试Js很方便

为游戏狂~~!!    大家努力编哈!
2012-02-14 14:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-357281-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.110757 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved