【问题标题】:parameter not being passed in javascript plugin, html syntax issue?参数未在 javascript 插件中传递,html 语法问题?
【发布时间】:2013-08-09 08:03:34
【问题描述】:

我正在使用一个名为 Prettyphoto 的插件,当您启动该插件时,您可以传递一个名为 social_tools 的参数,您可以在其中输入加载 Twitter 和 Facebook 按钮的 html。

js文件中的默认html本身是没有问题的,我也可以将html添加到js文件中就可以了。

但是当我尝试添加启动插件的代码时,它停止工作。

我最终看到的只是屏幕上输出的}); });,好像某处没有正确关闭。

我在本地工作。

这是我的代码

 <script type="text/javascript" charset="utf-8">
 $(document).ready(function(pp_settings){
 $("a[rel^='prettyPhoto']").prettyPhoto({
        social_tools: '<div class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="facebook"><iframe src="//www.facebook.com/plugins/like.php?locale=en_US&href={location_href}&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:23px;" allowTransparency="true"></iframe></div>' 
                });
 });

 </script>

这里你可以看到参数列表,如果你向下滚动到自定义,最后你会social_tools

http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/documentation

谢谢

【问题讨论】:

    标签: javascript jquery html prettyphoto


    【解决方案1】:

    &lt;script&gt; 元素实际上在第一次使用 &lt;/script&gt; 时结束,尽管它在 String 文字中放置或使用。

    防止这种情况的常见技巧是将其分解:

    '...</' + 'script>...'
    

    【讨论】:

    • 谢谢,解决了问题
    【解决方案2】:

    这也行不通吗?

        var options = {social_tools: '<div class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="facebook"><iframe src="//www.facebook.com/plugins/like.php?locale=en_US&href={location_href}&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:23px;" allowTransparency="true"></iframe></div>'};
    
    $(document).ready(function(pp_settings){
         $("a[rel^='prettyPhoto']").prettyPhoto(options);
    });
    

    【讨论】:

    • 谢谢,但现在这个...'}; $(document).ready(function(pp_settings){ $("a[rel^='prettyPhoto']").prettyPhoto(options); }); 正在屏幕上输出
    • 如果您可以在 jsfiddle.net 上发布有问题的代码,我们可以为您提供更多帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 1970-01-01
    • 2016-07-02
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多