我有打字稿代码
就这个
$('.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);
}
});
在这段代码中,我有 2 个错误
在这一行$(this).parent().find('input:checkbox').attr('checked', true);
我有
'true' 类型的参数不能分配给 '(index: number, attr: string) => string | 类型的参数 数字'。
而在这
$(`#stops_${this.id.split('_')[1]}`).val(`Max ${$( this ).slider("value")} ${__('byten')}`);
类型“TElement”上不存在属性“id”。
我该如何解决?
在第一种情况下,使用:
$(this).parent().find('input:checkbox').prop('checked', true);
因为使用attr
你只会得到属性的初始值,如果设置。prop
给出属性的当前值。
对于第二种情况,请使用:
$(this).attr('id').
或者
this.getAttribute('id')
代替
this.id
希望这能为您服务。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句