我想顯示文本1A當李項被點擊,但由於某種原因,它顯示了在同一時間文本1A 1B 1C,而我只對文字感興趣在點擊的範圍內。我試圖利用'這個',但沒有運氣。 小提琴例子是這裏=>https://jsfiddle.net/5x4xbuf9/顯示文本
$('li.listItem').on('click',function(){
var showText = $('span.a').text();
alert(showText)
})
<li class = "listItem"><span class ="a">1a</span><span class ="b">2a</span></li>
<li class = "listItem"><span class ="a">1b</span><span class ="b">2b</span></li>
<li class = "listItem"><span class ="a">1c</span><span class ="b">2c</span></li>