function showHint()
{   
if(document.getElementById('uname').value == "" || document.getElementById('upwd').value){
alert("用户名或密码不能为空!");
return false;
           }
if(document.getElementById('area').value==""){
alert("您的评论不能为空!");
return false;
             }
}<form action='act.php' method='post' name='login' >
<table width='640' style='border:1px solid #ccc' align='center'>
  <tr>
    <td width='9%' class='brd'>用户名</td>
    <td width='28%' class='brd'><input name='uname' id='uname' type='text'  size='23'/></td>
    <td width='9%' class='brd'>密&nbsp;&nbsp;码</td>
    <td width='29%' class='brd'><input type='password' name='upwd'  id='upwd' size='23'  /></td>
    <td width='8%' class='brd'><input type='submit' value='登录'  /></td>
    <td width='17%' class='brd'>注册</td>
  </tr>
</table>
<input type='hidden' name='sign' value='' />
</form> 为什么这个js没用呢?

解决方案 »

  1.   

    写掉了一句:onsubmit='return check()' 
      

  2.   

    要我我把代码全贴出来吧php文件
    echo"<form action='act.php' method='post' name='login' onsubmit='return check()' >
    <table width='640' style='border:1px solid #ccc' align='center'>
      <tr>
        <td width='9%' class='brd'>用户名</td>
        <td width='28%' class='brd'><input name='uname' id='uname' type='text'  size='23'/></td>
        <td width='9%' class='brd'>密&nbsp;&nbsp;码</td>
        <td width='29%' class='brd'><input type='password' name='upwd'  id='upwd' size='23'  /></td>
        <td width='8%' class='brd'><input type='submit' value='登录'  /></td>
        <td width='17%' class='brd'>注册</td>
      </tr>
    </table>
    <input type='hidden' name='sign' value='' />
    </form> ";<div id="submit">
    <form action="" method="post" name="message" onSubmit="return showHint()">
    <table align="center" class="nobrd"> 
      <tr>
         <td width="660" colspan="6" align="center" class='brd'><textarea name="area"  id="area" style="border:1px dashed #966; height:60px; width:640px; text-align:left; overflow-y:auto"><?= $text ?></textarea></td>
       </tr>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="nobrd" >
       <tr>
        <td> <input type="submit" value="提交" /></td>
            </tr>
         </table>    
    </form>
    </div>js文件function showHint()
    {   
    if(document.getElementById('uname').value == "" || document.getElementById('upwd').value){
    alert("用户名或密码不能为空!");
    return false;
    }
    if(document.getElementById('area').value==""){
    alert("您的评论不能为空!");
    return false;
    }
    var xmlhttp;
    if (str.length==0)
       { 
       document.getElementById("txtHint").innerHTML="";
      return;
       }
    if (window.XMLHttpRequest)
       {// code for IE7+, Firefox, Chrome, Opera, Safari
       xmlhttp=new XMLHttpRequest();
      }else
       {// code for IE6, IE5
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
    xmlhttp.onreadystatechange=function()
       {
       if (xmlhttp.readyState==4 && xmlhttp.status==200){
         document.getElementById("addtext").innerHTML=xmlhttp.responseText;
         }
        }
      

  3.   

    为什么只能检测用户注册,不能检测textarea呢?本人对js一知半解
      

  4.   

    document.formName.textareaName.innerText == "";
      

  5.   

    document.getElementById('upwd').value==""
      

  6.   

    <?= $text ?>  是什么?你先删掉试试