Why does the verification pass or fail? the value of required is undefind, so I can't judge whether the verification is successful or not.

< input name= "" type= "text" required / >

Mar.10,2021

required only requires the user to fill in.

has nothing to do with whether the check is successful or not.

in addition, if you want to get the result of require=true , your input can write

like this.

required dom getAttribute()

API

input.validity
input.validity.valid
input.validity.badInput

input.validationMessage
input.setCustomValidity
input.formNoValidate
input.willValidate

input.addEventListener('invalid' , function () {
    input.setCustomValidity('')
  console.log(input.validationMessage)
})
Menu