html5 oninvalid doesn't work after fixed the input field

前端 未结 5 1637
故里飘歌
故里飘歌 2020-12-06 01:08

I have this input code in my form:



        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 02:05

    You can set a custom validity message with setCustomValidity, however any non-blank string will cause the field to act as if it had an invalid value. You need to setCustomValidity('') to clear the invalidated state of the field.

    If your validity is simple and controlled via field attributes, you can use object.willValidate to do the test and set the custom validity message:

    oninvalid="this.setCustomValidity(this.willValidate?'':'your custom message')"

提交回复
热议问题