0

我正在尝试使用 jquery 添加社交喜欢值(Twitter、Facebook、GooglePlus、Pinterest、电子邮件帐户)。这是我的html代码。

<div class="social-likes">
<span class='st_twitter_vcount' displayText='Tweet' st_via=""></span>
<span class='st_facebook_vcount' displayText='Facebook'></span>
<span class='st_googleplus_vcount' displayText='Share'></span>
<span class='st_pinterest_vcount' displayText='Pinterest'></span>
<span class='st_email_vcount' displayText='Email'></span>

<span id="total_shares"></span> // Display the total
</div>

这是jquery代码。

<script type="text/javascript">

var TweetCount    = jQuery('.st_twitter_vcount .stBubble .stBubble_count').text();
var FacebookCount   = jQuery('.st_facebook_vcount .stBubble .stBubble_count').text();
var GooglePlusCount = jQuery('.st_googleplus_vcount .stBubble .stBubble_count').text();
var PinInterestCount= jQuery('.st_pinterest_vcount .stBubble .stBubble_count').text();
var EmailCount    = jQuery('.st_email_vcount .stBubble .stBubble_count').text();
var TotalShares   = parseInt(TweetCount) + parseInt(FacebookCount) + parseInt(GooglePlusCount) + parseInt(PinInterestCount) + parseInt(EmailCount);
jQuery('#total_shares').text(TotalShares );
Alert(TotalShares);

</script>

当我尝试检查浏览器上的每个元素时,代码就是这些。

<span class="st_twitter_vcount" st_via="" displaytext="Tweet" st_processed="yes">
 <span class="stButton" style="text-decoration:none;color:#000000;display:inline- block;cursor:pointer;">
  <div>
    <div style="display: block;" class="stBubble">
        <div class="stBubble_count">0</div>
    </div>
  </div>
 </span>

<span class="st_facebook_vcount" displaytext="Tweet" st_processed="yes">
 <span class="stButton" style="text-decoration:none;color:#000000;display:inline- block;cursor:pointer;">
  <div>
    <div style="display: block;" class="stBubble">
        <div class="stBubble_count">12</div>
    </div>
  </div>
 </span>

.... 和别的...

但是当我尝试将警报放入脚本时,它返回一个未定义的值(NaN)。我错过了什么吗?请帮助我,我是 jquery/javascript 的新手。我的目标是这样的。http://mashable.com/2013/11/05/voice-impressions-video/ 。获取总份额。

4

0 回答 0