“HTMLElement”类型中不存在“已检查”属性。 [英] Property 'checked' does not exist on type 'HTMLElement'.

查看:133
本文介绍了“HTMLElement”类型中不存在“已检查”属性。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在打字稿文件中有这个代码

I have this code in typescript file

 function debug_show_removed_flights() {
    if ($('.debug-window #show_removed_flights')[0].checked) {
      $('.fly-schedule-removed_reason').show();
      return $('.fly-schedule-remove').show();
    } else {
      $('.fly-schedule-removed_reason').hide();
      return $('.fly-schedule-remove').hide();
    }
  };

但在这一行中,我有错误。

But in this row, I have error.

if ($('.debug-window #show_removed_flights')[0].checked) {




[ts]'HTMLElement'类型中不存在'已检查'属性。

[ts] Property 'checked' does not exist on type 'HTMLElement'.

我如何解决?

推荐答案

HTMLInputElement 拥有已检查的财产。您可以转换元素以便它可以转换:

Only HTMLInputElement have the checked property. You can cast your element so it will transpile:

function debug_show_removed_flights() {
    const input = $('.debug-window #show_removed_flights')[0] as HTMLInputElement;
    if (input.checked) {
        $('.fly-schedule-removed_reason').show();
        return $('.fly-schedule-remove').show();
    } else {
        $('.fly-schedule-removed_reason').hide();
        return $('.fly-schedule-remove').hide();
    }
}

这篇关于“HTMLElement”类型中不存在“已检查”属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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