简体   繁体   English

下面的代码有什么问题?

[英]What's wrong in the code below?

I get a console error: 'Uncaught SyntaxError: Unexpected token -' What's wrong? 我收到控制台错误:“未捕获的SyntaxError:意外令牌-”出了什么问题? Please, may anyone help? 请,有人可以帮忙吗?

  $(document).ready(function() {

    $("#widget_settings_holder").find(".tbLanguageTabs").first().tabs();

      var cmpt-br = CodeMirror.fromTextArea(document.getElementById("text_widget_text_pt-br"), {
      mode:        "htmlmixed",
      lineNumbers: true,
      tabMode:     "indent"
    });

    $(tbApp).off("tbWidget:onUpdate.textWidget").one("tbWidget:onUpdate.textWidget", function(event, $widget, $form) {

      if ($widget.attr("id").split("_")[1] != "HtmlWidget") {
          return;
      }

          cmpt-br.toTextArea();
          $form.find("textarea[name$='[text]']").each(function() {
        $(this).val(utf8_to_b64($(this).val()));
      });
    });

  });
  var cmpt-br = 

- is a subtraction operator . -减法运算符 You can't use it in a variable name. 您不能在变量名中使用它。

Javascript doesn't allow dashes in the name of variables. Javascript不允许在变量名称中使用破折号。

So your line 所以你的线

var cmpt-br = CodeMirror.fromTextArea(document.getElementById("text_widget_text_pt-br"), {

Is incorrect because of the name of your variable. 由于变量名称不正确。 You can use underscore for your purpose. 您可以根据需要使用下划线。

var cmpt_br = CodeMirror.fromTextArea(document.getElementById("text_widget_text_pt-br"), {
var cmpt-br = 

Use an underscore, not a hyphen. 使用下划线,而不是连字符。 JavaScript evaluates it as an expression. JavaScript将其评估为表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM