HTML:我可以知道這些警報之間的區別嗎?還需要關於attr的一些提示?
<div class="abc">
<span data-rel="hai">Hello</span>
<span data-rel="bye">Bye</span>
</div>
的jQuery:
$(document).on('click','.abc >span',function(){
alert(($(this).attr('data-rel'))); // This Code alerts hai.
alert($('.'+($(this).attr('data-rel'))+'_cls')); // I thought this code would alert as .hai_cls but it alerts as [object object].
});
我能知道這有什麼區別?
爲什麼它會提醒同樣的事情?在一個提醒'rel'數據屬性的值中,一個提醒jQuery的值CSS類選擇器查找。兩個都有一對不必要的parens。 –