【问题标题】:Uncaught SyntaxError: Unexpected token = (Chrome)Uncaught SyntaxError: Unexpected token = (Chrome)
【发布时间】:2015-03-15 00:07:02
【问题描述】:

我一直在我的控制台日志中收到此消息(仅适用于 chrome):

Uncaught SyntaxError: Unexpected token

它在 Firefox 上运行良好。

我做了一些研究,它说 Chrome 不支持命名参数。但是我在发现错误的第 131 行没有任何命名参数。

下面是我正在使用的代码。任何帮助将不胜感激!

 var id = checkbox_element.attr('id');
 var recurring_cycle_dropdown = $("#recurring_cycle");
 var label = $("label#" + id);

 //Display the radio options pricing method when the payment  type checkbox has been checked
 if (checkbox_element.is(":checked")) {
     /*If the checkbox id is recurring show the  recurring cycle right
      * after the label next to the radio button, */
     if(id == "recurring"){
         label.after(recurring_cycle_dropdown.show(0, function(){
             //The $(this) is referring to the  recurring_cycle_dropdown
             //not the checkbox
             $(this).css("display","block");

             //****THIS IS THE LINE WHERE THE ERROR IS FOUND****
             $(this).prop("disabled",false);
         }));
     }

【问题讨论】:

  • 我没有发现任何明显的问题。 (id 应该是唯一的,因此您的标签和复选框不应使用彼此相同的 id,但这对于显示的代码无关紧要。)

标签: javascript jquery


【解决方案1】:

如果您在代码中使用默认参数,就会发生这种情况。 Javascript 不允许这样做,但 Firefox 以某种方式推翻了它。

【讨论】:

    【解决方案2】:

    我发现了问题所在。其中一个函数(不在我提供的代码中)在参数上有一个默认值。我删除了默认值,代码现在可以工作了!感谢您的帮助!

    【讨论】:

    • 我给出了相同的解决方案。如果对您有帮助,您可以将其标记为答案。
    猜你喜欢
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 2012-01-31
    • 2013-11-11
    • 2019-03-18
    • 2012-05-17
    • 2019-02-10
    • 2014-07-08
    相关资源
    最近更新 更多