我试图在facebook + googleplus中自动分享地址栏
我的Html + js代码:
<a class="facebook" target="_blank" href="">Facebook</a>
<a class="googleplus" target="_blank" href="">Google+</a>
<script>
document.getElementById("facebook").href = "http://www.facebook.com/sharer.php?u=" + window.location.href;
document.getElementById("googleplus").href = "http://plus.google.com/u/0/share?url=" + window.location.href;
</script>
空结果
如何修复此空结果
答案 0 :(得分:2)
您的目标是ID,而非目标:
document.getElementById("facebook").href = "http://www.facebook.com/sharer.php?u=" + window.location.href;
document.getElementById("googleplus").href = "http://plus.google.com/u/0/share?url=" + window.location.href;
<a id="facebook" target="_blank" href="">Facebook</a>
<a id="googleplus" target="_blank" href="">Google+</a>