【问题标题】:MIssing ) after argument list for jQuery in WordPressMIssing ) 在 WordPress 中 jQuery 的参数列表之后
【发布时间】:2017-10-10 18:25:37
【问题描述】:

我仍在学习中,我在控制台中遇到了这个错误。

你可以找到测试页面的链接[here][1]

missing ) after argument list

对于这个 jQuery 代码:

    jQuery.noConflict();
 (function ($) {
     function readyFn() {
     $.fn.extend({
         Segment: function ( ) {
       $(this).each(function (){
         var self = $(this);
         var onchange = self.attr('onchange');
         var wrapper = $("<div>",{class: "ui-segment"});
         $(this).find("option").each(function (){
           var option = $("<span>",{class: 'option',onclick:onchange,text: $(this).text(),value: $(this).val()});
           if ($(this).is(":selected")){
             option.addClass("active");
           }
           wrapper.append(option);
         });
         wrapper.find("span.option").click(function (){
           wrapper.find("span.option").removeClass("active");
           $(this).addClass("active");
           self.val($(this).attr('value'));
         });
         $(this).after(wrapper);
         $(this).hide();
       });
         }
     });

 $(".segment-select").Segment();

 var options = {
   monthly: [
         {price: 25, link: 'link1'},
             {price: 45, link: 'link2'},
                 {price: 145, link: 'link3'},
     ],
     yearly: [
         {price: 300, link: 'link4'},
             {price: 540, link: 'link5'},
                 {price: 640, link: 'link6'},
     ]
 }

 function fillContent(interval) {
     var data = options[interval];

   $('.content').each(function(index) {
       var content = $(this);

         content.find('span.price').text('$' + data[index]span.price);
         content.find('span.interval').text(interval);
         content.find('span.link').attr('href', data[index]span.link);

     });
 }

 // initialization

 fillContent("monthly");

 $('.ui-segment').on("click", '.option', function() {
   var interval = $(this).attr('value');

     fillContent(interval);
 });
     }

     $(document).ready(readyFn);
 })(jQuery);

会有什么问题?我确实在指向代码的content.find('span.price').text('$' + data[index]span.price); 部分的控制台中看到了这个错误。

Image: Error in console

【问题讨论】:

  • span 应该在data[index]span.price 中是什么?不应该只是data[index].price吗?
  • 好吧,你可能会说。我把它改回.price,但这没有用。另外,当我检查元素时,它会显示span.price。如果我错了,请纠正我。
  • DOM 元素与您尝试访问的对象没有任何关系。
  • 明白。好吧,尝试了不同的价格变化。在页脚中加载脚本也不起作用。有什么建议吗?

标签: jquery syntax


【解决方案1】:

对于我在这里看到的,你的 jquery.noConflict();它没有以正确的方式关闭,请尝试按照以下代码进行操作:

jQuery.noConflict();
 (function ($) {
     function readyFn() {
     $.fn.extend({
         Segment: function ( ) {
       $(this).each(function (){
         var self = $(this);
         var onchange = self.attr('onchange');
         var wrapper = $("<div>",{class: "ui-segment"});
         $(this).find("option").each(function (){
           var option = $("<span>",{class: 'option',onclick:onchange,text: $(this).text(),value: $(this).val()});
           if ($(this).is(":selected")){
             option.addClass("active");
           }
           wrapper.append(option);
         });
         wrapper.find("span.option").click(function (){
           wrapper.find("span.option").removeClass("active");
           $(this).addClass("active");
           self.val($(this).attr('value'));
         });
         $(this).after(wrapper);
         $(this).hide();
       });
         }
     });
     }
 });

 $(".segment-select").Segment();

 var options = {
   monthly: [
         {price: 25, link: 'link1'},
             {price: 45, link: 'link2'},
                 {price: 145, link: 'link3'},
     ],
     yearly: [
         {price: 300, link: 'link4'},
             {price: 540, link: 'link5'},
                 {price: 640, link: 'link6'},
     ]
 }

 function fillContent(interval) {
     var data = options[interval];

   $('.content').each(function(index) {
       var content = $(this);

         content.find('span.price').text('$' + data[index]span.price);
         content.find('span.interval').text(interval);
         content.find('span.link').attr('href', data[index]span.link);

     });
 }

 // initialization

 fillContent("monthly");

 $('.ui-segment').on("click", '.option', function() {
   var interval = $(this).attr('value');

     fillContent(interval);
 });

     $(document).ready(readyFn);

【讨论】:

  • 谢谢。但是这不起作用Unexpected end of input
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-02
  • 1970-01-01
  • 2017-11-04
  • 1970-01-01
  • 2013-03-11
  • 2018-06-15
  • 1970-01-01
相关资源
最近更新 更多