我要做到以下幾點:我可以結合jQuery選擇器嗎?
$("#dat_chk" + (i)).css("background-color", "#f6FFee");
$("#dat_opt" + (i)).css("background-color", "#f6FFee");
$("#dat_txt" + (i)).css("background-color", "#f6FFee");
是這些方法,我可以縮短到只有一個使用jQuery選擇?
我要做到以下幾點:我可以結合jQuery選擇器嗎?
$("#dat_chk" + (i)).css("background-color", "#f6FFee");
$("#dat_opt" + (i)).css("background-color", "#f6FFee");
$("#dat_txt" + (i)).css("background-color", "#f6FFee");
是這些方法,我可以縮短到只有一個使用jQuery選擇?
$('.class').css("background-color", "#f6FFee");
$("#dat_chk" + i + ", #dat_opt" + i + ", #dat_txt" + i).css("background-color", "#f6ffee");
檢查語法 – Teneff
是。用,
它們分開:
$("#dat_chk" + (i) + ", #dat_opt" + (i) + ", #dat_txt" + (i)).css("background-color", "#f6FFee");
var selector = '#dat_chk' + i + ', #dat_opt' + i + ', #dat_txt' + i;
$(selector).css("background-color", "#f6FFee");
試試這個
$("#dat_chk" + i + ", #dat_opt" + i + ", #dat_txt" + i).css("background-color", "#f6FFee");
的選擇應該是這樣的:
$("#dat_chk" + i + ", #dat_opt" + i + ", #dat_txt" + i)
易哥們:
$("#dat_chk" + (i) + ", #dat_opt" + (i) + ", #dat_txt" + (i)).css("background-color", #f6FFee");
除了使用逗號分隔符,你也可以使用.add
:
$("#dat_chk" + i)
.add("#dat_opt" + i)
.add("#dat_txt" + i)
.css(...);
這是http://stackoverflow.com/questions/1752718/how-的副本做我選擇多於一個元素的使用jQuery的屬性選擇器? – JMax
使用逗號分開選擇器,您可以在單個jquery語句中使用它 – abhijit