如何onsubmit每个class?

How onsubmit each class?

我有很多文本区域,我想检查输入长度。 不超过10个字不能投稿。 它会提醒,但仍然提交。

function checkinput(){
  $('.TextArea').each(function() {
      var textl = $(this).val().length;
      if ( textl < 10 && (EndTime.getTime()-Time != 0)) {
          window.alert ( "answer need large 10 word!" );
          return false;
      }
  });
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

 <form method="POST" action="answer.php" id="form" onsubmit="return checkinput();">

为函数返回 false 的情况添加 event.preventDefault()

function checkinput(event){
  $('.TextArea').each(function() {
      var textl = $(this).val().length;
      if ( textl < 10 && (EndTime.getTime()-Time != 0)) {
          event.preventDefault();
          window.alert ( "answer need large 10 word!" );
          return false;
      }
  });
  return true;
}

function checkinput() {
  //create an event listener for click on your submit button 
  $('#submit').click(function(e) {
    // define a variable to hold textareas
    let $Textarea = $('.TextArea');
    // run a loop on each textarea
    $Textarea.each(function(i, v) {
      // variable for each instance of textarea being triggered using keyword this
      let input = $(this).val();
      // split the value at each word using a blank space
      let words = input.split(' ');
      // check the length of the split array and see if there is 10 values present
      if (words.length < 10) {
        window.alert("Textarea " + i + " - answer need large 10 word!");
        // preventDefault() keeps the form from submitting and refreshing the DOM    
        e.preventDefault();
        return false;
      }
    });
  });
}


checkinput();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<form method="POST" action="answer.php" id="form">
  <textarea class='TextArea'></textarea>
  <textarea class='TextArea'></textarea>
  <textarea class='TextArea'></textarea>
  <textarea class='TextArea'></textarea>
  <button id='submit'>Submit</button>
</form>