html-js案例1

来源:互联网 发布:泰安东华软件股份公司 编辑:程序博客网 时间:2024/06/02 04:31

非空验证:

<!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>吕老师视频-http://www.tudou.com/home/xuexi158</title>
<script type="text/javascript">
    //定义函数来做表单中控件的验证
    function validateForm(){
        //获得控件的值,然后进行内容的判断
        var myName = document.form1.userName.value;//得到用户名的值
        if(myName==""){
            alert("用户名不能为空!!!");
            return false;
        }       
        return true;
    }
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="rw7.html"
onsubmit="return validateForm()"><!-- 触发事件 调用函数 -->
  <table width="450" border="1" align="center">
    <tr>
      <td colspan="2">用户登录:</td>
    </tr>
    <tr>
      <td>用户名:</td>
      <td><label>
        <input type="text" name="userName" id="userName" />
      </label></td>
    </tr>
    <tr>
      <td>密码:</td>
      <td><input type="password" name="userPass" id="userPass" /></td>
    </tr>
    <tr>
      <td><label>
        <input type="submit" name="button" id="button" value="登录" />
      </label></td>
      <td><label>
        <input type="reset" name="button2" id="button2" value="重置" />
      </label></td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
</body>
</html>
 

原创粉丝点击