[HTML 5] preventDefault() & defaultPrevented prop

2021-03-18 07:25

阅读:444

标签:span   sign   app   turn   box   round   asc   input   value   

const app = document.getElementById(app);
app.innerHTML = `
  

JavaScript DOM

`; 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


评论


亲,登录后才可以留言!