[HTML 5] preventDefault() & defaultPrevented prop
2021-03-18 07:25
标签:span sign app turn box round asc input value [HTML 5] preventDefault() & defaultPrevented prop 标签:span sign app turn box round asc input value 原文地址:https://www.cnblogs.com/Answer1215/p/12775120.htmlconst app = document.getElementById(‘app‘);
app.innerHTML = `
`;
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);
JavaScript DOM
文章标题:[HTML 5] preventDefault() & defaultPrevented prop
文章链接:http://soscw.com/index.php/essay/65676.html