首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >参数类型为“字符串”的参数“{##}\ string[]‘”不能分配给“字符串”类型的参数。

参数类型为“字符串”的参数“{##}\ string[]‘”不能分配给“字符串”类型的参数。
EN

Stack Overflow用户
提问于 2019-04-12 07:05:17
回答 1查看 1.1K关注 0票数 1

我编写了ajQuery代码来确定高度和宽度,并单击功能。代码如下:

代码语言:javascript
复制
$(document).ready(function(){
      console.log("Jquery is working!");
      adjustBar();
      $(window).on('resize', function() {
        adjustBar();
      })
    $('#height').on('input change', function() {
        var height = $(this).val();
        if (height >= 30) {
        var leftOffset = (Math.tan(45 * (Math.PI / 180)) * (height / 2) + 3) * -1;
        $('.steps').css('height', height).css('line-height', height + "px").css('left', leftOffset + "px");
        adjustBar();
      }
    });
    $('.steps').on('click', function() {
      $('.steps').removeClass('active');
      $(this).addClass('active');
    })
  });
  function adjustBar() {
      var items = $('.steps').length;
      var elHeight = $('.steps').height() / 2; //Division by 2 because each pseudo which is skewed is only 50% of its parent.
      var skewOffset = Math.tan(45 * (Math.PI / 180)) * elHeight;
      var reduction = skewOffset + ((items - 1) * 4);
      var leftOffset = $('.steps').css('left').replace('px', '');
      var factor = leftOffset * (-1) - 2;
      $('.steps').css({
        'width': '-webkit-calc((100% + 4px - ' + reduction + 'px)/' + items + ')'
      }); // 4px for borders on either side
      $('.steps:first-child, .steps:last-child').css({
        'width': '-webkit-calc((100% + 4px - ' + reduction + 'px)/' + items + ' + ' + factor + 'px)'
      }); // 26px because to make up for the left offset. Size of last-child is also increased to avoid the skewed area on right being shown  
      $('.steps span').css('padding-left', (skewOffset + 15) + "px");
      $('.steps:first-child span, .steps:last-child span').css({
        'width': '-webkit-calc(100% - ' + factor + 'px)'
      });
    }  

当我运行该代码时,我会得到以下错误:

错误TS2362:算术操作的左边必须是'any‘、'number’、'bigint‘或枚举类型。event-viewer/event-viewer.component.ts(34,35):error TS2345:参数类型为'string string not string[]‘,不能分配给'string string number not(此处: HTMLElement,index: number,value: string) => string string number index’的参数。键入'string[]‘不能指定键入'string欧元编号’(这是: HTMLElement,index: number,value: string),=> \x,string,not,void)‘。键入“string[]”不能指定键入“string”。event-viewer/event-viewer.component.ts(49,20):error TS2362:算术操作的左侧必须是'any‘、'number’、'bigint‘或枚举类型。

heightwidthleftoffset似乎被认为是字符串,但它们应该是由网页中元素的位置来计算的数值。我怎样才能纠正这些错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-12 09:23:12

应该将字符串值转换为数字。您可以使用:var height = Number($(this).val());

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55646224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档