不能使用$('。foo')。on('click','。bar',使用jQuery和TypeScript [英] Can't use $('.foo').on('click', '.bar', with jQuery and TypeScript

查看:95
本文介绍了不能使用$('。foo')。on('click','。bar',使用jQuery和TypeScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用TypeScript和jQuery,我需要在上使用jQuery的来收听事件:

I am using TypeScript and jQuery in a project and I need to use jQuery's on to listen to an event:

const $previewListWrp: jQuery<HTMLElement> = $('.js-preview-list-wrp').first();

$previewListWrp.on('click', '.btn-action.remove', (evt: Event): void => {
  let $box: JQuery<HTMLElement> = $(evt.target).closest('.js-preview-wrp');
  console.log($box.data());
});

然而,我收到错误


类型'click'的参数不能赋值给'PlainObject void> |类型的参数EventHandlerBase

Argument of type '"click"' is not assignable to parameter of type 'PlainObject void> | EventHandlerBase

刚开始一个新项目并安装了最新版本的TypeScript,jQuery和@ types / jQuery。

Just started a new project and installed the latest versions of TypeScript, jQuery and @types/jQuery.

推荐答案

尝试将evt:EventTarget更改为evt: JQuery.Event

try changing evt: EventTarget to evt: JQuery.Event

这篇关于不能使用$('。foo')。on('click','。bar',使用jQuery和TypeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆