javascript插件中未传递参数,html语法问题

parameter not being passed in javascript plugin, html syntax issue?

本文关键字:html 语法 问题 参数 插件 javascript      更新时间:2023-09-26

我使用的是一个名为Prettphoto的插件,当你启动该插件时,你可以传递一个称为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

感谢

<script>元素实际上在</script>的第一次使用时结束,尽管它被放置或使用在String文本中。

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

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

这也不起作用吗?

    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);
});