首页 > 代码库 > input元素required属性无效

input元素required属性无效

解决方法出自 http://stackoverflow.com/questions/23261301/required-attribute-not-work-in-safari-browser

 

Safari不支持input的required属性,可用js解决

 1 $(document).ready(function(){
 2     $("form").submit(function(e) {
 3         var ref = $(this).find("[required=required]");
 4         alert(‘ref‘);
 5         $(ref).each(function(){
 6             if ( $(this).val() == ‘‘ )
 7             {
 8                 alert("Required field should not be blank.");
 9                 $(this).focus();
10                 e.preventDefault();
11                 return false;
12             }
13         });  return true;
14     });
15 });

 

本文原创,转载请注明出处:http://www.cnblogs.com/lawn-tiger/p/6346726.html

input元素required属性无效