gpt4 book ai didi

javascript - 类型 'true' 的参数不可分配给类型的参数

转载 作者:行者123 更新时间:2023-12-03 02:11:39 25 4
gpt4 key购买 nike

我有 typescript 代码

这就是它

$('.Switch').on('click', function() {
if ($(this).hasClass('On')) {
$(this).parent().find('input:checkbox').attr('checked', true);
$(this).removeClass('On').addClass('Off');
$(this).parent().find('input:hidden').val(0);
$(".filter_stops").each(function() {
if ($(this).slider( "option", "value" ) === 0) {
$(this).off('slidechange');
$(this).slider( "option", "value", 99 );
$(`#stops_${this.id.split('_')[1]}`).val(`Max ${$( this ).slider("value")} ${__('byten')}`);
$(`#filter_stops_${this.id.split('_')[1]}`).val($( this ).slider("value"));
$(this).on('slidechange', FilterFunctions.onFilterChange);
}
});

在此代码中我有两个错误

在这一行$(this).parent().find('input:checkbox').attr('checked', true);我有

Argument of type 'true' is not assignable to parameter of type '(index: number, attr: string) => string | number'.

在这个

 $(`#stops_${this.id.split('_')[1]}`).val(`Max ${$( this ).slider("value")} ${__('byten')}`);

Property 'id' does not exist on type 'TElement'.

我该如何解决这个问题?

最佳答案

在第一种情况下,使用:

$(this).parent().find('input:checkbox').prop('checked', true);

因为使用attr,您只能获得属性的初始值(如果已设置)。 prop 给出属性的当前值。

对于第二种情况,使用:

$(this).attr('id').

this.getAttribute('id')

而不是

this.id

希望这对您有用。

关于javascript - 类型 'true' 的参数不可分配给类型的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49535806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com