iPad/iPhone上的"必需"Html5表单元素不起作用

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尚不支持:我什么时候可以使用:必需.

  • 对苹果感到羞耻. (20认同)
  • 对Apple x1000感到羞耻!自从被问到这个问题以来,已经有3年,6个月和4天(截至本文),Apple仍然没有实施它.傲慢是令人难以置信的.Applesoft 2.0 ...... (9认同)
  • 2016年2月,Apple仍然糟透了. (7认同)
  • 2016年7月仍然没有工作¬¬ (2认同)
  • 2016年9月,iPhone 7发布,iOS 10发布,仍然无法正常工作.干得好的Apple! (2认同)
  • 如链接所示,Safari 10.1和iOS 10.3(均发布于27.03.2017)支持所需的属性. (2认同)

小智 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)