The global <a data-l10n-name="mdn-beforeinput">beforeinput</a> event is fired on an <a data-l10n-name="mdn-input">&lt;input&gt;</a> and <a data-l10n-name="mdn-textarea">&lt;textarea&gt;</a> elements, or any element whose <a data-l10n-name="mdn-contenteditable">contenteditable</a> attribute is enabled, immediately before the element’s value changes. The event allows web apps to override the browser’s default behavior for user interaction, e.g., web apps can cancel user input only for specific characters or can modify pasting styled text only with approved styles.
在 <a data-l10n-name="mdn-input">&lt;input&gt;</a>、<a data-l10n-name="mdn-textarea">&lt;textarea&gt;</a>，以及任何启用 <a data-l10n-name="mdn-contenteditable">contenteditable</a> 属性的元素的值变更前，会触发全局的的 <a data-l10n-name="mdn-beforeinput">beforeinput</a> 事件。此事件可让 Web 应用程序覆盖浏览器的默认用户交互行为（例如：应用程序可阻止用户输入某些特殊字符，或只允许以特定的样式修改粘贴的文本）。