【网页设计】验证表单是否为空
2014-11-16 12:01
246 查看
在做登录注册页面的时候,需要检测用户是否合法输入,其中重要的一条就是,验证表单的信息是否为空
下面以一个账号密码登录表单为例,说一下用Javascript的一个解决方案
JavaScript中的函数:
Htnl表单
获取username的另外方式:
var username=document.getElememntByID('username').value;
设置焦点的另外方式:
document.getElementById("username").focus();
下面以一个账号密码登录表单为例,说一下用Javascript的一个解决方案
JavaScript中的函数:
<script type="text/javascript"> function validate() { if(document.myform.username.value=="") { alert("用户名不能为空."); document.myform.username.focus(); return false ; } if(document.myform.password.value=="") { alert("密码不能为空."); document.myform.password.focus(); return false ; } return true; } </script>
Htnl表单
<form action="load" method="post" name="myform" id="myform" onsubmit="return validate()"> <input type="text" name="username" style="width:190px; height:26px;"/><br/> <input type="password" name="password" style="width:190px; height:26px; margin-top:12px;"/><br/> <input type="submit" value="登录" style="width:50px; height:30px; margin-top:8px;"/> </form>
获取username的另外方式:
var username=document.getElememntByID('username').value;
设置焦点的另外方式:
document.getElementById("username").focus();
相关文章推荐
- 通达oa工作流表单设计使用ajax+jquery 验证用户是否存在
- JS验证(网页设计中表单数据的验证)
- 设计自动获取网页和提交表单组件
- (转)使用validwhen设计复杂的Struts表单验证
- 网页表单设计实例技巧五则
- 网页注册表单的网页设计技巧
- 网页设计关于表单输入框的技巧代码
- 网页表单验证代码的改进
- 使用validwhen设计复杂的Struts表单验证
- jQuery formValidator表单验证插件,适合行业网页(表单元素密集型)的表单验证示例(转载)
- 表单设计中的网页视觉体验
- js表单验证是否空值的简单处理办法
- CSS设计符合Web标准的网页表单的几个技巧
- (转)使用validwhen设计复杂的Struts表单验证
- 设计自动获取网页和提交表单组件
- (转)网页表单验证代码的改进
- 网页设计之5种简单的XHTML网页表单
- 在struts框架下数据库表单与网页表单的设计
- 网页表单制作和验证过程
- js验证符合用户体验的网页表单特效