标签:span sign app turn box round asc input value
const app = document.getElementById(‘app‘); app.innerHTML = ` <h1>JavaScript DOM</h1> <form> <label> Sign-up Email <input type="email"> </label> <label> I agree to the terms <input type="checkbox"> </label> </form> `; const form = document.querySelector(‘form‘); const email = form.querySelector(‘input[type="email"]‘); const checkbox = form.querySelector(‘input[type="checkbox"]‘); function handleSubmit(event) { if (!checkbox.checked) { event.preventDefault(); console.log(‘I am not submitting...‘); console.log(event.defaultPrevented); // true return; } console.log(‘Submitted‘, email.value); } form.addEventListener(‘submit‘, handleSubmit);
[HTML 5] preventDefault() & defaultPrevented prop
标签:span sign app turn box round asc input value
原文地址:https://www.cnblogs.com/Answer1215/p/12775120.html