簡體   English   中英

舊版瀏覽器無法識別`javascript

[英]older browsers won't recognize ` in javascript

我正在構建一個帶有基礎范圍滑塊的計算器。 它適用於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);
  }
});

如果我將`改為',它在任何瀏覽器中都不起作用。 任何人有任何想法? 謝謝!

如果您必須支持舊瀏覽器,那么您唯一真正的選擇是不使用模板文字。 它是JavaScript中的一個相對較新的功能,因此舊版瀏覽器無法理解如何解釋它。

這里是文檔的鏈接,顯示了它的支持:

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

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

這個

 `${movement}%`

成為這個:

 movement + "%"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM