Son*_*Box 19 forms html5 mobile-safari required html-validation
iPad safari应该符合html5标准,但似乎所需的元素不起作用.任何人都知道为什么,或者有一个不需要大量JavaScript的体面解决方案?
我的代码
<input type=email class=input placeholder="Email" name="email" required>
Run Code Online (Sandbox Code Playgroud)
Ian*_*lin 25
iOS尚不支持:我什么时候可以使用:必需.
小智 16
这是该问题的jQuery解决方案,它突出显示了以小指颜色失败的输入字段.
$('form').submit(function(){
var required = $('[required="true"]'); // change to [required] if not using true option as part of the attribute as it is not really needed.
var error = false;
for(var i = 0; i <= (required.length - 1);i++)
{
if(required[i].value == '') // tests that each required value does not equal blank, you could put in more stringent checks here if you wish.
{
required[i].style.backgroundColor = 'rgb(255,155,155)';
error = true; // if any inputs fail validation then the error variable will be set to true;
}
}
if(error) // if error is true;
{
return false; // stop the form from being submitted.
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29669 次 |
| 最近记录: |