我有功能,这是代码
function remove_multi_leg(): void {
if (Number($("#search_no_legs").val()) < 2) {
return;
}
const removeId: number = Number($(this).attr("data-number"));
const highestId: number = Number($("#search_no_legs").val());
if (removeId === highestId) {
$(`#multi_leg_${removeId}`).hide();
$("#search_no_legs").val(highestId);
return;
}
let i: number;
let end: number;
let asc : boolean;
for (i = removeId, end = highestId, asc = removeId <= end; asc ? i <= end : i >= end; asc ? i += 1 : i -= 1) {
$(`#search_legs_${i}_origin_text`).val($(`#search_legs_${i + 1}_origin_text`).val());
$(`#search_legs_${i}_origin_id`).val($(`#search_legs_${i + 1}_origin_id`).val());
$(`#search_legs_${i}_destination_text`).val($(`#search_legs_${i + 1}_destination_text`).val());
$(`#search_legs_${i}_destination_id`).val($(`#search_legs_${i + 1}_destination_id`).val());
}
$(`#multi_leg_${highestId - 1}`).hide();
$("#search_no_legs").val(highestId - 1);
return;
}
但是当代码分析代码时我有一个奇怪的错误
就这个
the "this" keyword is disallowed outside of a class body
在这一行
const removeId: number = Number($(this).attr("data-number"));
我该如何解决?