我想運行一個函數取決於數據屬性的值。 但它總是返回false
當我運行此:jQuery的 - 數據()=='東西'總是返回false
alert(jQuery(this).data('loaded') == 'no');
但我的數據屬性設置爲無,當我提醒
alert(jQuery(this).data('loaded'));
它返回正確的數據屬性值。
更新
HTML
<a class="btn" href="#" data-loaded="no"></a>
的代碼全部
jQuery('a').click(function(e) {
e.preventDefault();
if (jQuery(this).data('loaded') == 'no'){
ajax();
jQuery(this).attr('data-loaded', 'yes');
}
});
什麼是您的HTML看起來像(或相關的代碼,你設定的屬性)? – Blender 2013-05-11 00:41:11
更新了我的問題 – user007 2013-05-11 00:43:28
'$('').data('loaded')=='no''對我返回'true' 。你的上下文中的「this」是什麼? – Blender 2013-05-11 00:44:29