我在typescript文件中有这段代码
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();
}
};
但在这一行中,我有错误。
if ($('.debug-window #show_removed_flights')[0].checked) {
[ts]'HTMLElement'类型中不存在'已检查'属性。
我该如何解决?
答案 0 :(得分:8)
只有HTMLInputElement
具有checked属性。你可以投射你的元素,以便它可以转换:
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();
}
}