$(".focus-button").addClass('active');
$(".focus-button[data-expand='true']").addClass('active');
使用可變控股選擇。如果我存儲在像變量的類選擇:在Javascript
var btn = $(".focus-button");
變量可以在代碼中使用
btn.addClass('active'); // This is correct
btn[data-expand='true'].addClass('active'); // This is wrong
我可以知道是使用變量和屬性的正確方法。
'filter' http://api.jquery.com/filter/'btn.filter( 「[數據展開= '真']」)' –