你的位置:首页 > 软件开发 > 网页设计 > button 按钮,结合onclick事件,验证和提交表单

button 按钮,结合onclick事件,验证和提交表单

发布时间:2016-11-28 14:00:32
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&qu ...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html ="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <style type="text/css"></style> <script type="text/javascript"> //button 按钮,结合onclick事件,验证和提交表单 function checkForm(){    //判断用户名是否为空    if(document.form1.username.value==""){        window.alert("用户名不能为空");    }else if(document.form1.username.value.length<5 || document.form1.username.value.length>20){      window.alert("用户名长度必须介于5-50个字符之间!");    }else{      //使用form对象的submit()方法,实现提交。      document.form1.submit();        } } </script> </head> <body> <form name="form1" method="get" action="login.php"> 用户名:<input type="text" name="username" /> 密码:<input type="password" name="userpwd" /> <input type="button" value="提交表单" onclick="checkForm()" /> </form> </body></html>

原标题:button 按钮,结合onclick事件,验证和提交表单

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录