JS点击事件:简单的客户端校验

<html>
  <head>
    <title>点击事件</title>
    <meta http-equiv="content-type" 
    content="text/html; charset=UTF-8">
    <script type="text/javascript">
        function toSubmit(){
            var username=document.getElementById
            ("username").value;

            if(username==""){//客户端JS验证
                alert("请输入用户名");
                return;
            }
            document.getElementById("info").submit();   
        }
    </script>
  </head>
  <body>
    <form action="http://www.baidu.com" id="info" >
        用户名:<input  type="text" value="" id ="username"/>
              <input type="button" value="提交" 
              onclick="toSubmit()"/>
    </form>

  </body>
</html>
posted @ 2016-11-22 17:14  第五个世界  阅读(172)  评论(0编辑  收藏  举报