首页 > 其他 > 详细

modernizr框架之表单验证

时间:2015-05-17 18:47:20      阅读:226      评论:0      收藏:0      [点我收藏+]

框架下载地址:http://modernizr.com/


案例:

<!DOCTYPE html>
<html> 
  <head>
    <script src="http://code.jquery.com/jquery-1.7.1.js"></script>
    <script src="http://ajax.cdnjs.com/ajax/libs/modernizr/1.7/modernizr-1.7.min.js">
    </script>
 
    <script type="text/javascript">
       $(function(){
			  if( !Modernizr.input.required ){
			    var $msg = $( "<div id='reqMessage'>Required Fields Missing</div>" );
			    $msg.css( "background-color", "yellow" )
			        .hide();
			   
			    $( "body" ).append( $msg );
			 
			    $( "#fDet" ).on( "submit", function(e){
						      $( "input[required]" ).each(function(){
								        if ( $( this ).val() === "" ) {
								          $( "#reqMessage" ).show();
								          $( this ).css( "border" , "1px solid red" );
								          e.preventDefault();
								        }   
						      }); 
			    });
			  }
}); 
</script>
</head>
<body>
<form id="fDet" action="#">
<input type="text" name="userName" required/>
<input type="password" name="password" required/>
<input type="submit" value="send it" />
</form>
</body>
</html>



modernizr框架之表单验证

原文:http://blog.csdn.net/luozhonghua2014/article/details/45789827

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!