質問

iPad SafariはHTML5準拠であると想定されていますが、必要な要素が機能しないようです。誰もがなぜjavascriptのトンを必要としないまともな回避策を持っているのかを誰でも知っていますか?

私のコード

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

役に立ちましたか?

解決

IOSではまだサポートされていません。使用できます。必須

他のヒント

これは問題への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.
    }
});
.

iOS 10.3以降、この属性はサポートされています。電子メールタイプには@シンボルなどを書く必要があります...

既にjQuery、Modernizr、Yepnopeを使用している場合、これを対処する1つの方法です。あなたがそうでなければ、これは多くの追加のJavaScriptを追加します。

My Solution

私はこのような提出行動の前に何かをすることができると思います

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

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

詳細な説明のための>

PHPを使用している場合は、こののような検証を追加できます。

function validation(){

  if(isset($_POST['submit'])){
  $email = $_POST['email'];

     if(empty($email)){
        echo $error = "Your email cannot be empty";

      } else {
        return true; //or do something next here
     }
   }
.

あなたはあなたの形の前にphpでこの関数を追加します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top