Bur*_*urt 2 javascript jquery social-networking google-plus-one
我正在建立一个基于滑块的图片库,并通过javascript加载新图片,并且需要通过javascript设置Google +1按钮的网址,因此可以在每张图片上设置+1.
我还需要根据每个图像重新加载+1按钮(该URL将包含一个包含图像ID的查询字符串参数,以使其唯一).这可能吗?
小智 5
<!-- Place this tag where you want the +1 button to render -->
<div class="g-plusone" data-annotation="inline" data-href="#"></div>
<!-- Place this render call where appropriate -->
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
Run Code Online (Sandbox Code Playgroud)
您可以使用以下代码使用jQuery更改gplus href属性.确保首先包含jquery库,然后使用以下代码:
<script type="text/javascript">
jQuery(".your-button").click(function(){
jQuery(".g-plusone").attr("data-href","Your-Value-Goes-Here");
});
</script>
Run Code Online (Sandbox Code Playgroud)