RT<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<script>
function chekName(){
var name=document.getElementById("textfield").value;
var pass=document.getElementById("textfield2").value;
if(name==""){
document.getElementById("tishizhanghao").innerHTML="账号不能为空";

}}
</script>
<table width="444" height="212" border="1">
  <tr>
    <td width="65">账号</td>
    <td width="168"><form id="form1" name="form1" method="post" action="">
      <label>
        <input type="text" name="textfield" onblur="chekName()" />
        </label>
    </form>    </td>
    <td width="189"><span id="tishizhanghao"></span></td>
  </tr>
  <tr>
    <td>密码</td>
    <td><form id="form2" name="form2" method="post" action="">
      <label>
        <input type="text" name="textfield2" />
        </label>
    </form>    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><form id="form3" name="form3" method="post" action="">
      <label>
      <input type="submit" name="Submit" value="提交" />
      </label>
      <label>
      <input type="submit" name="Submit2" value="重置" />
      </label>
    </form>    </td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
JavaScript

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head>
     
    <body>
    <script>
    function chekName(){
    //除ie以外的浏览器的getElementById不对name起作用
        //var name=document.getElementById("textfield").value;
        //var pass=document.getElementById("textfield2").value;

    //另外你用户名密码应当在同一个form下面,而不是拆成两个form,
    //一次提交只会提交一个form下面的所有表单项内容
    var name= form1.textfield.value;
    var pass= form1.textfield2.value;    if(name==""){
            document.getElementById("tishizhanghao").innerHTML="账号不能为空";
         
        }
     
    }
    </script>
    <table width="444" height="212" border="1">
      <tr>
        <td width="65">账号</td>
        <td width="168"><form id="form1" name="form1" method="post" action="">
          <label>
            <input type="text" name="textfield" onblur="chekName()" />
            </label>
        <!--去掉一个form </form> -->    </td>
        <td width="189"><span id="tishizhanghao"></span></td>
      </tr>
      <tr>
        <td>密码</td>
        <td><!--去掉一个form <form id="form2" name="form2" method="post" action=""> -->
          <label>
            <input type="text" name="textfield2" />
            </label>
        </form>    </td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><form id="form3" name="form3" method="post" action="">
          <label>
          <input type="submit" name="Submit" value="提交" />
          </label>
          <label>
          <input type="submit" name="Submit2" value="重置" />
          </label>
        </form>    </td>
        <td>&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>
      

  2.   

    搞哪么些form干吗?放在一起不行吗
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <script type="text/javascript">
    function chekName(){
    var name=document.getElementById("textfield").value;
    if(name==""){
    document.getElementById("tishizhanghao").innerHTML="账号不能为空";

    }}
    </script>
    <form id="form1" name="form1" method="post" action="">
    <table width="444" height="212" border="1">
      <tr>
        <td width="65">账号</td>
        <td width="168">
          <label>
            <input type="text" name="textfield" id="textfield" onblur="chekName()" />
            </label>
       </td>
        <td width="189"><span id="tishizhanghao"></span></td>
      </tr>
      <tr>
        <td>密码</td>
        <td colspan="2">
          <label>
            <input type="text" name="textfield2" />
            </label>
    </td>
      </tr>
      <tr>
        <td colspan="3">
          <label>
          <input type="submit" name="Submit" value="提交" />
          </label>
          <label>
          <input type="submit" name="Submit2" value="重置" />
          </label>
        </td>
        
      </tr>
    </table>
    </form>
    </body>
    </html>
      

  4.   

    问题不在与form不form的问题,
    问题是  楼主的JS是document.getElementById,但是标签却没有id属性
    所以 给input加id