【问题标题】:I got error : "missing) after argument list"我收到错误:“参数列表后缺少”
【发布时间】:2019-06-14 04:40:56
【问题描述】:

出现错误:

在参数列表之后缺少 )

$('.next-btn').append("<a class="actionsubmit" ng-click="onSubmit('hello.html')">Check</a>");

【问题讨论】:

  • 哦-好吧,现在很明显-因为您假设javascript知道"何时标记字符串的开头和结尾
  • $('.next-btn').append("检查") ;这是我得到错误的代码
  • "&lt;a class=" 是一个字符串 ... 紧跟在 actionsubmit 之后是无效的 - 你需要转义你的内心 " ... 像 $('.next-btn').append("&lt;a class=\"actionsubmit\" ng-click=\"onSubmit('hello.html')\"&gt;Check&lt;/a&gt;");
  • 提供更多细节。
  • 欢迎来到 Stack Overflow。这只是一个语法问题。如果你使用" 来包装你的字符串数据,它也会以" 结束。如果需要,可以在里面使用'

标签: javascript jquery jquery-ui


【解决方案1】:

看起来您需要在附加字符串中转义特殊字符,

$('.next-btn').append("<a class=\"actionsubmit\" ng-click=\"onSubmit('hello.html')\">Check</a>");

【讨论】:

    【解决方案2】:

    错误是由语法问题产生的。

    您的代码:

    $('.next-btn').append("<a class="actionsubmit" ng-click="onSubmit('hello.html')">Check</a>");
    

    你不能在这个字符串中使用"而不转义它。例如:

    $('.next-btn').append("<a class=\"actionsubmit\" ng-click=\"onSubmit('hello.html')\">Check</a>");
    

    请阅读:https://www.w3schools.com/js/js_strings.asp

    因为字符串必须写在引号内,JavaScript 会误解这个字符串:

    var x = "We are the so-called "Vikings" from the north.";

    字符串将被截断为“我们是所谓的”。避免此问题的解决方案是使用反斜杠转义字符。反斜杠 (\) 转义字符将特殊字符转换为字符串字符。

    现在您还可以在 jQuery 中创建元素。建议代码:

    var newA = $("<a>", {
      class: "actionsubmit",
      "ng-click": "onSubmit('hello.html')"
    }).html("Check");
    $('.next-btn').append(newA);
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-08
      • 1970-01-01
      • 1970-01-01
      • 2018-03-09
      • 2018-02-04
      • 2017-09-01
      相关资源
      最近更新 更多