Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Ghi đè validation HTML5


Để bỏ qua validation HTML, bạn có thể gỡ thuộc tính required khi click button bằng JavaScript.

Dùng removeAttribute() để gỡ thuộc tính khỏi các phần tử khớp.

<!DOCTYPE html> <html>    <body>       <form>          First Name: <input type = "text" id = "fname" value = "Amit" required>          <input type = "radio" onclick = "dislay('fname')"><br>       </form>       <script>          function display(id) {             document.getElementById(id).value = document.getElementById(id).removeAttribute('required');          }       </script>    </body> </html>