19

iPad safari は html5 に準拠しているはずですが、必要な要素が機能していないようです。誰かが理由を知っているか、大量の JavaScript を必要としない適切な回避策を持っていますか?

私のコード

<input type=email class=input placeholder="Email" name="email" required>
4

6 に答える 6

25

iOS ではまだサポートされていません: when can I use: required .

于 2012-05-19T10:48:48.877 に答える
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.
    }
});
于 2014-10-16T14:36:55.407 に答える
1

このような送信アクションの前に何かできると思います

<form name="myForm" action="valid.html" onsubmit="checkValid()" method="post">
  ... ...
</form>

submitボタンを押した後、checkValid()実際に送信する前に呼び出されます。の戻り値はtrue送信アクションを続行します。

詳細については、この投稿を参照してください。:)

于 2015-11-19T08:24:00.317 に答える
1

すでに jQuery、Modernizr、および yepnope を使用している場合、これはそれに対処する 1 つの方法です。そうでない場合、これにより多くの余分な JavaScript が追加されます。

私の解決策

于 2012-10-23T22:06:01.273 に答える