【问题标题】:JSlint: Unexpected string concatenation errorJSlint:意外的字符串连接错误
【发布时间】:2018-06-21 02:48:30
【问题描述】:

出现意外的字符串连接错误,

我的所有功能都运行良好,但它显示了意外的字符串连接错误

$this.find('.content > .component:gt(' + (limit - 1) + ')').hide();

我使用了以下,但功能不起作用,

$this.find(`.content > .component:${limit - 1}`).hide();

【问题讨论】:

  • .component:N 不是有效的选择器。您是否在寻找 :eq() 以通过索引选择元素?
  • 是的,我通过使用内部类 .component 来带来索引计数
  • 我的问题有什么问题,字符串连接在不同的场景中会带来很多错误,如果你在职业生涯初期遇到这个问题,你可以了解我的情况......

标签: jquery error-handling compiler-errors jslint


【解决方案1】:

我们必须使用模板文字而不是字符串连接。

$this.find(`.content > .component:gt(' ${limit- 1} ')`).hide();

在函数中调用值时应该使用反引号“`”,并且应该使用 (' ${} ')

参考如下, https://eslint.org/docs/rules/prefer-template

【讨论】:

  • 谢谢@Lanka Patrudu
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-29
  • 1970-01-01
  • 2016-03-01
  • 2015-07-30
  • 2022-10-25
  • 2023-03-26
相关资源
最近更新 更多