Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery添加社会喜欢值_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用jquery添加社会喜欢值

Javascript 使用jquery添加社会喜欢值,javascript,jquery,html,Javascript,Jquery,Html,我正在尝试使用jquery添加社交喜好值(Twitter、Facebook、GooglePlus、Pinterest、emailaccount)。这是我的html代码 <div class="social-likes"> <span class='st_twitter_vcount' displayText='Tweet' st_via=""></span> <span class='st_facebook_vcount' displayText='Fa

我正在尝试使用jquery添加社交喜好值(Twitter、Facebook、GooglePlus、Pinterest、emailaccount)。这是我的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>

var TweetCount=jQuery('.st_twitter_vcount.stBubble.stBubble_count').text();
var FacebookCount=jQuery('.st_facebook_vcount.stBubble.stBubble_count').text();
var googlepluscont=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(googlepluscont)+parseInt(PinInterestCount)+parseInt(EmailCount);
jQuery('total#u shares').text(TotalShares);
警报(总股份);
当我尝试在浏览器中检查每个元素时,代码如下所示

<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>

0


12
。。。。和其他


但当我试图将警报放入脚本时,它返回一个未定义的值(NaN)。我错过什么了吗?请帮助我,我是jquery/javascript新手。我的目标是这样的。获取总共享。

TweetCount、FacebookCount等的分配是什么?另外,是否需要“.stBubble”和“.stBubble_count”类选择器?哪里是
stBubble
&
stBubble_count
元素???您的HTML不包含任何可以读取和解析的数字。我更新了我的问题。对Id不包含任何元素。我认为这是内部HTML。试试这个
jQuery('.st\u twitter\u vcount.stBubble.stBubble\u count').HTML()。。。使用
html()
而不是
text()
<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>