31

リスト ボックスとテキスト エリアを備えた単純なページを作成し、すべてが必要な条件を設定しました。

リスト ボックスは正常に動作していますが、テキストエリア ボックスは、フィールドに入力する必要があることを示していません。

<!DOCTYPE html>
<html>
<head>
<title>Ratings & Reviews</title>
<body>
<form>

<span>Customer Service*</span>
<span>
    <select name=customer id=aa required>
        <option selected="rate" value="" disabled>rate</option>
        <option value=1>1</option>
        <option value=2>2</option>
        <option value=3>3</option>
        <option value=4>4</option>
        <option value=5>5</option>
    </select>
</span>
<br><br>
<span>Value for money*</span>
<span>
    <select name=money id=aa required>
        <option selected="rate" value="" disabled>rate</option>
        <option value=1>1</option>
        <option value=2>2</option>
        <option value=3>3</option>
        <option value=4>4</option>
        <option value=5>5</option>
    </select>
</span>

<div>
    <textarea name="reviews" rows=11 cols=50 maxlength=250 required>
    </textarea>
</div>

<div id=submit>
    <br>
    <input type=submit name=submit value=submit>
</div>

</form>
</body>
</html>
4

7 に答える 7

82

テキスト領域内に空のスペースがあります。それを削除します。

 <textarea name="reviews" rows=11 cols=50 maxlength=250 required ></textarea>

フィドルのデモ

于 2013-06-12T09:01:57.310 に答える
15

問題は、タグ間のスペースにあります。これらのタグの間に html のスペースを入れてはいけません。そうしないと、ブラウザーはそれを値と見なします。

于 2013-06-12T09:03:27.493 に答える
3

そしておそらくフォームにはnovalidate属性があります。フォームnovalidate 属性を持つフォーム要素の検証属性 (requiredまたは などregexp)は無視されます。

于 2017-09-02T00:35:34.523 に答える
2

同様の問題に直面しました。次のコードのように、Textareaの開始タグと終了タグの間にスペースを残しました

<label><b>Register As:*</b></label>
<select name="category" id="category" class="form-control"  
 onchange="toggleInput()" required>
      <option value=''>--Select--</option>
      <option value='Attendee'>Attendee</option>
      <option value='Presenter'>Presenter</option>
</select>

 ...
<textarea name="description" id="description" class="form-control" 
placeholder="Explain here what you will present...">  </textarea>

そして私のjavascriptで私は次のことを試みていました

<script>
   function toggleInput() {  
      if( document.getElementById("category").value=="Attendee"){  
        document.getElementById("description").required = false;
      }
      else{
        document.getElementById("description").required = true;
      }
   }//End Function
</script>

そして、このページにたどり着くまで、何が問題なのかわかりませんでした。スペースでした。解決策をありがとう@sinisake。私の経験を共有して誰かを助けることを願っています

于 2019-07-05T09:49:11.863 に答える
1

開始タグと終了タグの間にスペースを使用しないでください。

例えば:

<textarea required>**Don't put any space here**</textarea>

それはうまくいきます。

于 2021-03-27T09:54:03.680 に答える