旧浏览器在javascript中无法识别`

时间:2016-08-12 19:32:27

标签: javascript jquery safari cross-browser zurb-foundation

我正在构建一个带有基础范围滑块的计算器。它适用于Safari 9,适用于Mac和Windows的最新Chrome和Firefox,Edge 14.但它在Safari 8或IE 11中无效。在Safari 8中,我看到错误 SyntaxError:无效字符:'`' javascript代码如下所示:

Foundation.Move(moveTime, $hndl, function() {
  //adjusting the left/top property of the handle, based on the percentage calculated above
  $hndl.css(lOrT, `${movement}%`);

  if (!_this.options.doubleSided) {
    //if single-handled, a simple method to expand the fill bar
    _this.$fill.css(hOrW, `${pctOfBar * 100}%`);
  } else {
    //otherwise, use the css object we created above
    _this.$fill.css(css);
  }
});

如果我将`更改为',则它无法在任何浏览器中使用。任何人有任何想法?谢谢!

1 个答案:

答案 0 :(得分:3)

如果您必须支持旧浏览器,那么您唯一真正的选择是不使用模板文字。它是JavaScript中的一个相对较新的功能,因此旧版浏览器无法理解如何解释它。

这里是文档的链接,显示了它的支持:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

你总是可以回到“老式的方式”:

这个

 `${movement}%`

成为这个:

 movement + "%"
相关问题