<script >
function chkinput(form){
if(form.name.value==""){
alert('请输入用户名');
form.name.focus();
return false;
}
if(form.password.value == "" || form.password.value.length < 6){
alert('');
form.password.focus();
return false;
}
if(form.yzm.value == ""){
alert('');
form.check.focus();
return false;
}
if(form.yzm.value != form.yzm2.value){
form.check.select();
code(form);
return false;
}

function yzm(form){
var num1=Math.round(Math.random()*10000000);
var num=num1.toString().substr(0,4);
document.write("<img name=codeimg width=36 heigh=20 src='yzm.php?num="+num+"'>");
form.check2.value=num;
}function code(form){
var num1=Math.round(Math.random()*10000000);
var num=num1.toString().substr(0,4);
document.codeimg.src="yzm.php?num="+num;
form.check2.value=num;
}</script>
<body onLoad="javascript:login.name.focus()">
<form id="login" name="login" action="login.php" method="post" onSubmit="return chkinput(this)">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <table width="405" height="212" border="0" align="center" cellspacing="10" bgcolor="#CCFFFF">
    <caption>
    <span class="style1">    用户登录<br>
    </span>
    </caption>
    <tr>
      <td width="97" height="44" bgcolor="#CCFFFF"><div align="right"><span class="style3"> 用户名:</span></div></td>
      <td colspan="3"><input name="name" type="text" id="name" width="150" onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></td>
    </tr>
    <tr>
      <td height="44" bgcolor="#CCFFFF"><div align="center"><span class="style3">密 码:</span></div></td>
      <td colspan="3"><input name="password" type="password" id="password" width="150" onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></td>
    </tr>
    <tr>
      <td height="44" bgcolor="#CCFFFF"><div align="center"><span class="style3">验证码:</span></div></td>
      <td width="65"><input type="text" name="yzm" width="60"onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" >
      <input name ="yzm2" type="hidden" value=""></td>
      <td width="55" align="center" valign="middle"><script>yzm(login);</script></td>
      <td width="54" ><a href="#" onclick="javascript:code(login)" style=" cursor:hand">换一张</a></td>
    </tr>
    <tr>
      <td height="44" colspan="4" bgcolor=""><div align="center">
        <input name=submit src="denglu.jpg" type="image" width="72" height="23" border="0" onClick="javascript:chkinput(login)"></div></td>
    </tr>
  </table>
</form>
运行后按了提交后调用不了javascript函数,那个超级连接也没有用了

解决方案 »

  1.   

    javascript:code(login)放到href中就可以了
      

  2.   

    如<a href="javascript:code(login)" style="cursor:hand">换一张 </a>
      

  3.   

    function chkinput(form){ 
    if(form.name.value==""){ 
    alert('请输入用户名'); 
    form.name.focus(); 
    return false; 

    if(form.password.value == "" || form.password.value.length < 6){ 
    alert(''); 
    form.password.focus(); 
    return false; 

    if(form.yzm.value == ""){ 
    alert(''); 
    form.check.focus(); 
    return false; 

    if(form.yzm.value != form.yzm2.value){ 
    form.check.select(); 
    code(form); 
    return false; 
    } } // 这里少半个括号啦
      

  4.   

    form.check.focus(); 
    form.check2.value=num; 
    顺便问下lz,怎么没看到表单中有check或check2呢?
      

  5.   


    <script > 
    function chkinput(aa){ 
    if(aa.name.value==""){ 
    alert('请输入用户名'); 
    aa.name.focus(); 
    return false; 

    if(aa.password.value == "" || aa.password.value.length < 6){ 
    alert(''); 
    aa.password.focus(); 
    return false; 

    if(aa.yzm.value == ""){ 
    alert('请输入验证码'); 
    aa.check.focus(); 
    return false; 

    if(aa.yzm.value != num){ 
    alert('验证码输入不正确'); 
    code();//再刷新验证码
    aa.check.focus(); 
    return false; 

    if(aa.yzm.value != aa.yzm2.value){ 
    aa.check.select(); 
    code(aa); 
    return false; 

    }var num="";//先定义一个全局变量
    function code(){ 
    var num1=Math.round(Math.random()*10000000); 
    var num=num1.toString().substr(0,4); 
    document.login.picyzm.src="yzm.php?num="+num; 
    } </script> 
    <body onLoad="javascript:login.name.focus()"> 
    <form id="login" name="login" action="login.php" method="post"> 
      <p>&nbsp; </p> 
      <p>&nbsp; </p> 
      <table width="405" height="212" border="0" align="center" cellspacing="10" bgcolor="#CCFFFF"> 
        <caption> 
        <span class="style1">    用户登录 <br> 
        </span> 
        </caption> 
        <tr> 
          <td width="97" height="44" bgcolor="#CCFFFF"> <div align="right"> <span class="style3"> 用户名: </span> </div> </td> 
          <td colspan="3"> <input type="text" id="name" name="name" width="150" onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"> </td> 
        </tr> 
        <tr> 
          <td height="44" bgcolor="#CCFFFF"> <div align="center"> <span class="style3">密 码: </span> </div> </td> 
          <td colspan="3"> <input name="password" type="password" id="password" width="150" onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"> </td> 
        </tr> 
        <tr> 
          <td height="44" bgcolor="#CCFFFF"> <div align="center"> <span class="style3">验证码: </span> </div> </td> 
          <td width="65"> <input type="text" name="yzm" width="60"onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" > 
          <input name ="yzm2" type="hidden" value=""> </td> 
          <td width="55" align="center" valign="middle"><img name="picyzm" id="picyzm" src=""></td> 
          <td width="54" > <a href="#" onclick="javascript:code(login)" style=" cursor:hand">换一张 </a> </td> 
        </tr> 
        <tr> 
          <td height="44" colspan="4" bgcolor=""> <div align="center"> 
            <input name="submit" src="denglu.jpg" type="image" width="72" height="23" border="0" onClick="javascript:chkinput(this.form);return false;"> 
            </div> </td> 
        </tr> 
      </table> 
    </form>
    <script language="javascript"> code();//初始化验证码</script>
      

  6.   


    <script > 
    function chkinput(aa){ 
    if(aa.name.value==""){ 
    alert('请输入用户名'); 
    aa.name.focus(); 
    return false; 

    if(aa.password.value == "" || aa.password.value.length < 6){ 
    alert(''); 
    aa.password.focus(); 
    return false; 

    if(aa.yzm.value == ""){ 
    alert('请输入验证码'); 
    aa.check.focus(); 
    return false; 

    if(aa.yzm.value != num){ 
    alert('验证码输入不正确'); 
    code();//再刷新验证码
    aa.check.focus(); 
    return false; 

    }var num="";//先定义一个全局变量
    function code(){ 
    var num1=Math.round(Math.random()*10000000); 
    var num=num1.toString().substr(0,4); 
    document.login.picyzm.src="yzm.php?num="+num; 
    } </script> 
    <body onLoad="javascript:login.name.focus()"> 
    <form id="login" name="login" action="login.php" method="post"> 
      <p>&nbsp; </p> 
      <p>&nbsp; </p> 
      <table width="405" height="212" border="0" align="center" cellspacing="10" bgcolor="#CCFFFF"> 
        <caption> 
        <span class="style1">    用户登录 <br> 
        </span> 
        </caption> 
        <tr> 
          <td width="97" height="44" bgcolor="#CCFFFF"> <div align="right"> <span class="style3"> 用户名: </span> </div> </td> 
          <td colspan="3"> <input type="text" id="name" name="name" width="150" onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"> </td> 
        </tr> 
        <tr> 
          <td height="44" bgcolor="#CCFFFF"> <div align="center"> <span class="style3">密 码: </span> </div> </td> 
          <td colspan="3"> <input name="password" type="password" id="password" width="150" onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"> </td> 
        </tr> 
        <tr> 
          <td height="44" bgcolor="#CCFFFF"> <div align="center"> <span class="style3">验证码: </span> </div> </td> 
          <td width="65"> <input type="text" name="yzm" width="60"onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" > 
          <input name ="yzm2" type="hidden" value=""> </td> 
          <td width="55" align="center" valign="middle"><img name="picyzm" id="picyzm" src=""></td> 
          <td width="54" > <a href="#" onclick="javascript:code(login)" style=" cursor:hand">换一张 </a> </td> 
        </tr> 
        <tr> 
          <td height="44" colspan="4" bgcolor=""> <div align="center"> 
            <input name="submit" src="denglu.jpg" type="image" width="72" height="23" border="0" onClick="javascript:chkinput(this.form);return false;"> 
            </div> </td> 
        </tr> 
      </table> 
    </form>
    <script language="javascript"> code();//初始化验证码</script>
      

  7.   

    汗,楼主代码无中生有的地方不少啊。<script > 
    function chkinput(aa){ 
    if(aa.name.value==""){ 
    alert('请输入用户名'); 
    aa.name.focus(); 
    return false; 

    if(aa.password.value == "" || aa.password.value.length < 6){ 
    alert(''); 
    aa.password.focus(); 
    return false; 

    if(aa.yzm.value == ""){ 
    alert('请输入验证码'); 
    aa.yzm.focus(); 
    return false; 

    if(aa.yzm.value != num){ 
    alert('验证码输入不正确'); 
    code();//再刷新验证码
    aa.yzm.focus(); 
    return false; 

    }var num="";//先定义一个全局变量
    function code(){ 
    var num1=Math.round(Math.random()*10000000); 
    var num=num1.toString().substr(0,4); 
    document.login.picyzm.src="yzm.php?num="+num; 
    } </script> 
    <body onLoad="javascript:login.name.focus()"> 
    <form id="login" name="login" action="login.php" method="post"> 
      <p>&nbsp; </p> 
      <p>&nbsp; </p> 
      <table width="405" height="212" border="0" align="center" cellspacing="10" bgcolor="#CCFFFF"> 
        <caption> 
        <span class="style1">    用户登录 <br> 
        </span> 
        </caption> 
        <tr> 
          <td width="97" height="44" bgcolor="#CCFFFF"> <div align="right"> <span class="style3"> 用户名: </span> </div> </td> 
          <td colspan="3"> <input type="text" id="name" name="name" width="150" onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"> </td> 
        </tr> 
        <tr> 
          <td height="44" bgcolor="#CCFFFF"> <div align="center"> <span class="style3">密 码: </span> </div> </td> 
          <td colspan="3"> <input name="password" type="password" id="password" width="150" onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"> </td> 
        </tr> 
        <tr> 
          <td height="44" bgcolor="#CCFFFF"> <div align="center"> <span class="style3">验证码: </span> </div> </td> 
          <td width="65"> <input type="text" name="yzm" width="60"onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" > 
          <input name ="yzm2" type="hidden" value=""> </td> 
          <td width="55" align="center" valign="middle"><img name="picyzm" id="picyzm" src=""></td> 
          <td width="54" > <a href="#" onclick="javascript:code(login)" style=" cursor:hand">换一张 </a> </td> 
        </tr> 
        <tr> 
          <td height="44" colspan="4" bgcolor=""> <div align="center"> 
            <input name="submit" src="denglu.jpg" type="image" width="72" height="23" border="0" onClick="javascript:chkinput(this.form);return false;"> 
            </div> </td> 
        </tr> 
      </table> 
    </form>
    <script language="javascript"> code();//初始化验证码</script>
      

  8.   

    document.login.picyzm.src="yzm.php?num="+num; 
    这句代码我试了下不行啊我问题解决了,就少了个括号,郁闷的
    有些代码我复制过来的,忘记改了,太马虎了啊谢谢大家啊
    就是不知道我的分该给哪位好啊,又不能平均分的顺便再问个问题啊,我的随机码太小了,怎么样变大点啊,改了好几个地方都不行啊
      

  9.   

    不知道我的分该给哪位好啊,又不能平均分的
    re:
    给谁由你定!没领到分也不会怪你!我的随机码太小了,怎么样变大点啊,改了好几个地方都不行啊
    re:
    放大随机码的位数即可!不知要的是不是这样效果
      

  10.   

    我初学者问题比较多啊,
    <tr> 
          <td height="44" bgcolor="#CCFFFF"> <div align="center"> <span class="style3">验证码: </span> </div> </td> 
          <td width="65"> <input type="text" name="yzm" width="60"onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" > 
          <input name ="yzm2" type="hidden" value=""> </td> 
          <td width="55" align="center" valign="middle"><img name="picyzm" id="picyzm" src=""></td> 
          <td width="54" > <a href="#" onclick="javascript:code(login)" style=" cursor:hand">换一张 </a> </td> 
        </tr> 这个验证码输入框运行的时候为什么和上面两个框一样长的啊,设计的时候还好好的