假設你想這是一個按鈕點擊發生,你可以這樣做:Working Demo
jQuery的
$('button').click(function() {
// set up an array to store the invalid rows
var rows = new Array();
$('table tr')
// reset all rows before we validate
.removeClass("error")
// loop over each row
.each(function(i) {
// work out whether the fields are completed or not
var filledFieldCount = 0;
filledFieldCount += $("[name='scheduledatepick[" + i + "]']", this).val().length > 0 ? 1 : 0;
filledFieldCount += $("[name='schedulein[" + i + "]']", this).val() !== "--" ? 1 : 0;
filledFieldCount += $("[name='location[" + i + "]']", this).val().length > 0 ? 1 : 0;
// if the total completed fields for this row
// is greater than none and less than all
// then add the row to the invalid rows list
if (filledFieldCount > 0 && filledFieldCount < 3) {
rows.push(this);
}
});
// finally, change the background of the
// rows to mark them as invalid
if (rows.length > 0){
$(rows).addClass("error");
}
});
CSS
.error { background-color: red; }
@fina lForm你認真嗎? – schaitanya
看起來像是一個問題... – Town
@Town他重新編輯它,以包括一個問題。 – FinalForm