HTML:
<div class="views-row views-row-2 views-row-even">
<div class="sonuc">
<span>lorem ipsum dolor sit amet</span>
</div>
<div class="views-field views-field-nothing">
<span class="field-content"><a href="#" class="share">Share</a></span>
</div> <div class="sonucbg"></div>
</div>
<div class="views-row views-row-2 views-row-even">
<div class="sonuc">
<span>lorem ipsum dolor sit amet 2222</span>
</div>
<div class="views-field views-field-nothing">
<span class="field-content"><a href="#" class="share">Share</a></span>
</div> <div class="sonucbg"></div>
</div>
JS:
$('#share').click(function() {
var product_name = jQuery(".sonuc span").html();
FB.ui({
method: 'feed',
name: product_name,
}, function(response) {
if(response && response.post_id){}
else{}
});
});
当我点击我的.share
按钮时,弹出即可。但我想,例如单击第一个共享按钮,获取该文本。
我该怎么做?
答案 0 :(得分:0)
您需要根据点击的按钮在.sonuc span
实例中隔离views-row
的实例
试试这个:
$('.share').click(function() {
var product_name = $(this).closest('.views-row').find(".sonuc span").html();
/* FB code */
});
您目前拥有的内容将始终从页面中包含的第一个.sonic
获取HTML