“JavaScript Sprawdź, czy wejście jest puste” Kod odpowiedzi

Jeśli wartość wejściowa jest null, zrób coś

if(document.getElementById("question").value.length == 0)
{
    alert("empty")
}
Scary Salamander

Jak sprawdzić, czy wszystkie wejścia nie są puste w przypadku JavaScript

const inputFeilds = document.querySelectorAll("input");

const validInputs = Array.from(inputFeilds).filter( input => input.value !== "");

console.log(validInputs) //[array with valid inputs]
~Chirume

JavaScript Sprawdź, czy wejście jest puste

<!-- check if any input field in "Form" is empty using JS -->

<script type="text/javascript">
  function validateForm() {
    var a = document.forms["Form"]["answer_a"].value;
    var b = document.forms["Form"]["answer_b"].value;
    if (!a || !b) {
      alert("Please Fill All Required Fields");
      return false;
    }
  }
</script>

<form method="post" name="Form" onsubmit="return validateForm()" action="">
  <input type="text" name="answer_a" value="">
  <input type="password" name="answer_b" value="password">
</form>
Web Surfer

JavaScript Sprawdź, czy wejście jest puste

if(document.getElementById("question").value.length == 0)
{
    console.log("empty")
}
Zealous Zebra

Odpowiedzi podobne do “JavaScript Sprawdź, czy wejście jest puste”

Pytania podobne do “JavaScript Sprawdź, czy wejście jest puste”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu