如果中添加的字段值無效,則會觸發(fā)oninvalid事件。如果用戶在提交前忘記填寫表單,請?zhí)砑右粭l消息。
示例
您可以嘗試運(yùn)行以下代碼來了解如何實(shí)現(xiàn)oninvalid ?JavaScript 中的事件。
<!DOCTYPE html> <html> <body> <script> function resetFunct() { alert("The form was reset"); } </script> <form> Enter Name: <input type="text" required oninvalid = "alert('Fill the form before submitting!');" > <br> Enter birth month: <input type= "text"> <br> <input type = "submit"> <input type = "reset"> </form> </body> </html>
登錄后復(fù)制
以上就是在JavaScript中,"oninvalid"事件的用途是什么?的詳細(xì)內(nèi)容,更多請關(guān)注www.92cms.cn其它相關(guān)文章!