首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >MIssing )在WordPress中jQuery的参数列表之后

MIssing )在WordPress中jQuery的参数列表之后
EN

Stack Overflow用户
提问于 2017-05-12 00:11:05
回答 1查看 88关注 0票数 0

我仍然在学习技巧,并且在控制台中得到了这个错误。

您可以找到指向测试页面[here][1]的链接

代码语言:javascript
运行
复制
missing ) after argument list

对于此jQuery代码:

代码语言:javascript
运行
复制
    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

EN

Stack Overflow用户

发布于 2017-05-12 00:16:40

对于我在这里看到的,您的jquery.noConflict();它没有以正确的方式关闭,请尝试遵循以下代码:

代码语言:javascript
运行
复制
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);

票数 -1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43920692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档