//判部门是否为空
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, 2010
var 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;
}