What's wrong in the code below?

为君一笑 提交于 2020-01-21 14:45:34

问题


I get a console error: 'Uncaught SyntaxError: Unexpected token -' What's wrong? 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()));
      });
    });

  });

回答1:


 var cmpt-br = 

- is a subtraction operator. You can't use it in a variable name.




回答2:


Javascript doesn't allow dashes in the name of variables.

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"), {



回答3:


var cmpt-br = 

Use an underscore, not a hyphen. JavaScript evaluates it as an expression.



来源:https://stackoverflow.com/questions/34912374/whats-wrong-in-the-code-below

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!