编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛  
全能 ASP / PHP / ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
发新话题
打印

用户名文本框中无法获得焦点的问题

本主题由 静夜思 于 2008-6-1 16:04 审核通过

用户名文本框中无法获得焦点的问题

<!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>
<script language="javascript">
    function abc()
    {
        if(form1.textfield.value=="")
        {
            window.alert("用户名不能为空!");
            form1.textfield.focus();
        }
    }
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="263" height="121" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td width="70">用户名:</td>
      <td width="168"><label>
        <input type="text" name="textfield" />
      </label></td>
    </tr>
    <tr>
      <td>密 码:</td>
      <td><label>
        <input type="text" name="textfield2" />
      </label></td>
    </tr>
    <tr>
      <td colspan="2"><label>
        
        <div align="center">
          <input type="submit" name="Submit" value="提交" onclick="abc()" /> 
          <input type="submit" name="Submit2" value="清空" />
        </div>
      </label></td>
    </tr>
  </table>
</form>
</body>
</html>


代码如上所示,当用户名为空时,点击提交按钮后,无法在用户名的文本框中获得焦点,还请各位大侠指点一二!!

TOP

因为你的按钮是SUBMIT类型 !

TOP

<form id="form1" name="form1" method="post" action="" onsubmit="abc()" >试试?
Behind the glory of a lonely words
荣耀的背后刻着一道孤独......

TOP

发新话题