<form id="customerForm"> <label> First Name: <input id="firstName" required /> </label> <label> Social Security Number: <input id="ssn" required pattern="^d{3}-d{2}-d{4}$" title="Expected pattern is ###-##-####" /> </label> <input type="submit" /> </form>
解决方法
此时,Safari不支持“必需”输入属性.
http://caniuse.com/#search=required
http://caniuse.com/#search=required
要在Safari上使用“必需”属性,可以使用’webshim‘
1 – 下载webshim
2 – 放这个代码:
<head> <script src="js/jquery.js"></script> <script src="js-webshim/minified/polyfiller.js"></script> <script> webshim.activeLang('en'); webshims.polyfill('forms'); webshims.cfg.no$Switch = true; </script> </head>