判断表格中的一列是否有重复项
本站寻求有缘人接手,详细了解请联系站长QQ1493399855
//判部门是否为空var arr = [];$("[name^=departmentId_]").each(function(){if(!$(this).val()){isOk = false;var alert_lineDepartmentIsEmptyCanNotSave = "<%=alert_lineDepartmentIsEmptyCanNotSave %>";alertE(alert_lineDepartmentIsEmptyCanNotSave.replace("<prodTableNo>",$(this).closest("tr").find("[id^=prodTableNo_]").text()));return false;}else{arr.push($(this).val());}});//判断部门是否重复if( arr.length != $.unique( arr ).length ){isOk = false;alertE("<%=alert_departmentRepetition%>");return false; }
jQuery .unique()的使用var yearArray = new Array(2009, 2009, 2010, 2010, 2009, 2010);
$.unique(yearArray);
返回 2009, 2010, 2009, 2010var yearArray = new Array(2009, 2009, 2010, 2010, 2009, 2010);
yearArray.sort();
$.unique(yearArray);
返回 2010, 2009兼容ie的修改方式:
var yearArray = new Array(2009, 2009, 2010, 2010, 2009, 2010);
// still sort the array
yearArray.sort();
//$.unique(yearArray);
yearArray = uniqueArray(yearArray);function uniqueArray(a){temp = new Array();for(var i = 0; i < a.length; i ++){if(!contains(temp, a[i])){temp.length+=1;temp[temp.length-1] = a[i];}}return temp;
}
function contains(a, e){for(j=0;j<a.length;j++)if(a[j]==e)return true;return false;
}