【发布时间】:2016-11-10 06:48:26
【问题描述】:
我正在开发一个简单的自定义共享,用户将单击共享按钮,该按钮将显示共享选项列表,然后用户可以单击其中任何一个来共享页面。
我在CodePen 上有设置代码,不知道为什么它不起作用。
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<a class="share-btn" href="#">S</a>
<div class="share"><a href="http://www.facebook.com/sharer/sharer.php?u=http://domain.com"> F</a>
</div>
<div class="share"><a href="whatsapp://send?text=The text to share!" data-action="share/whatsapp/share">W</a></div>
<div class="share"><a href="http://twitter.com/intent/tweet?status=This is the Title+http://domain.com/article/this-is-article
">T</a></div>
</body>
</html>
jQuery(document).ready(function($) {
$('.share').click(function() {
var NWin = window.open($(this).prop('href'), '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');
if (window.focus) {
NWin.focus();
}
return false;
});
});
$(".share-btn").click(function() {
$(".share").toggle();
});
【问题讨论】:
-
嗯,可能是因为 $(this) 是没有名为 href 的属性的 div。
-
@lain,你说得有道理
-
@lain,你说得对,我把它改成了
this到'.share > a'
标签: javascript jquery share