Javascript 严格模式下不允许使用八进制文字

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36878850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 19:40:33  来源:igfitidea点击:

Octal literals are not allowed in strict mode

javascriptcssangular

提问by Hongbo Miao

I am using Angular 2.

我正在使用 Angular 2。

When I use this in SCSS file, it works well.

当我在 SCSS 文件中使用它时,它运行良好。

.text::after {
  content: "
styles: [``]
a0
styles: [`
    .text::after {
      content: "  ";
    }
`]
a0"; }

However, when I move it in

然而,当我把它搬进去

.text::after {
  content: "\00a0\00a0";  // now it's just a simple plain string
}

It shows:

表明:

Uncaught SyntaxError: Octal literals are not allowed in strict mode.

未捕获的 SyntaxError:在严格模式下不允许使用八进制文字。

I know codes in styles: [``]needs to be CSS codes.

我知道代码styles: [``]需要是 CSS 代码。

And I tried

我试过

  .text::after {
    content: "\u00a0\u00a0"
  }

But then the screen shows   directly. How can I write it correctly?

但随后屏幕  直接显示。我怎样才能正确地写呢?

回答by Ankit Singh

You need to escape it

你需要逃避它

##代码##

"use strict"is a new feature introduced in JavaScript 1.8.5 (ECMAScript version 5).

“use strict”是 JavaScript 1.8.5(ECMAScript 版本 5)中引入的一个新特性。

In which,

其中,

  • Octal numeric literals are not allowed
  • Escape characters are not allowed
  • see more...
  • 不允许使用八进制数字文字
  • 不允许使用转义字符
  • 查看更多...

回答by Nick

Or you can add u(unicode)before the \.

或者你也可以添加u(Unicode)的\

##代码##