1

对于 facebook 粉丝页面,我创建了一个静态 html 选项卡(https://www.facebook.com/jgsportevents/app_190322544333196),我想在其中使用链接的 jquery 插件,就像我在客户网站上所做的一样(http:// /tinyurl.com/c3bfz93)。Chained 插件位于选项卡的基本 script.js 中,如下所示:

(function($) {

$.fn.chained = function(parent_selector, options) { 

    return this.each(function() {

        /* Save this to self because this changes when scope changes. */            
        var self   = this;
        var backup = $(self).clone();

        /* Handles maximum two parents now. */
        $(parent_selector).each(function() {

            $(this).bind("change", function() {
                $(self).html(backup.html());

                /* If multiple parents build classname like foo\bar. */
                var selected = "";
                $(parent_selector).each(function() {
                    selected += "\\" + $(":selected", this).val();
                });
                selected = selected.substr(1);

                /* Also check for first parent without subclassing. */
                /* TODO: This should be dynamic and check for each parent */
                /*       without subclassing. */
                var first = $(parent_selector).first();
                var selected_first = $(":selected", first).val();

                $("option", self).each(function() {
                    /* Remove unneeded items but save the default value. */
                    if (!$(this).hasClass(selected) && 
                        !$(this).hasClass(selected_first) && $(this).val() !== "") {
                            $(this).remove();
                    }                        
                });

                /* If we have only the default value disable select. */
                if (1 == $("option", self).size() && $(self).val() === "") {
                    $(self).attr("disabled", "disabled");
                } else {
                    $(self).removeAttr("disabled");
                }
                $(self).trigger("change");
            });

            /* Force IE to see something selected on first page load, */
            /* unless something is already selected */
            if ( !$("option:selected", this).length ) {
                $("option", this).first().attr("selected", "selected");
            }

            /* Force updating the children. */
            $(this).trigger("change");             

        });
    });
};

/* Alias for those who like to use more English like syntax. */
$.fn.chainedTo = $.fn.chained;

})(jQuery);

$("#bestemming").chained("#sport"); /* or $("#series").chainedTo("#mark"); *///         Javascript Document

此外,我在标签的 index.html 文件中使用 [[script.js]] 调用标签的脚本页面,并使用 http://code.jquery.com/jquery-latest.min.js'> 调用 jquery。不幸的是,我无法让插件像在客户网站上那样工作。

出了什么问题?

更新

根据 Fabio Antunes 的回答,我更改了代码。不幸的是,它仍然无法正常工作。我已经更改了代码,但仍然没有效果。

4

1 回答 1

2

您的 jquery 被阻止,facebook 阻止来自非安全 url 的每个脚本,因此更改此:

http://code.jquery.com/jquery-latest.min.js

对此:

https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js

出于同样的原因,您的字体也被阻止的另一件事:

http://fonts.googleapis.com/css?family=Roboto+Condensed:300italic,400italic,700italic,400,700,300

您只需要将协议更改为 https

https://fonts.googleapis.com/css?family=Roboto+Condensed:300italic,400italic,700italic,400,700,300

编辑

您的代码还有一个错误,您没有正确加载 facebook javascript,使您的应用程序触发 javascript 错误,因此您的应用程序不会运行任何脚本

改变这个:

<script>
  FB.init({
    appId  : 'YOUR_APP_ID',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    oauth  : true // enable OAuth 2.0
  });
  FB.Canvas.setAutoResize();
</script>

对此:

<script>
  window.fbAsyncInit = function() {
  FB.init({
Uncaught ReferenceError: FB is not defined
    appId  : 'YOUR_APP_ID',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    oauth  : true // enable OAuth 2.0
  });
  FB.Canvas.setAutoResize();
  };
  // Load the SDK Asynchronously
      (function(d){
         var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement('script'); js.id = id; js.async = true;
         js.src = "//connect.facebook.net/en_US/all.js";
         ref.parentNode.insertBefore(js, ref);
       }(document));
</script>
于 2013-03-24T13:42:54.590 回答