使用JavaScript事件代表团更改模糊事件

发布于 2025-02-10 12:31:07 字数 439 浏览 1 评论 0原文

我有一个动态添加到DOM的表格,因此我必须使用事件委托。

我无法将其开火,在我看来,这个事件只能将其附加到输入元素上,

['change', 'blur'].forEach(event => {
  document.addEventListener(event, e => {
    if (e.target.closest('.dynamic-modal form input')) {
      const $input = e.target.closest('.dynamic-modal form input')
      console.log($input)
      // never logs on change and blur
    }

  })
})

该如何解决?

I have a form that is dynamically added to the DOM and therefore I have to use event delegation.

I can not get this to fire and it looks to me like this event can only be attached to an input element

['change', 'blur'].forEach(event => {
  document.addEventListener(event, e => {
    if (e.target.closest('.dynamic-modal form input')) {
      const $input = e.target.closest('.dynamic-modal form input')
      console.log($input)
      // never logs on change and blur
    }

  })
})

How can I go about solving this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文