<script language="javascript" src="http://www.cnblogs.com/Js/jquery.validate.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$.validator.addMethod('CheckCodeIsExists',function (value, element) {
var IsExists;
var txt = $("#<%=txtCollectorCode.ClientID%>").val();
var originalTxt = $("#<%=hid_OriginalCode.ClientID %>").val();
$.ajax({
type: "get",
url: "LeXinDeviceHandler.ashx?LeXinCollectorCode=" + txt ,
async: false,
success: function (data, textStatus) {
if(('<%=Action %>' == "NEW") ||('<%=Action %>' == "UPDATE" && txt!=originalTxt))
{
if (data == "true") {
IsExists="false"
}
else
{
IsExists="true"
}
}
}
});
if(IsExists=="false")
return false;
else
return true;
});
$.validator.addMethod('CheckSelect',function (value, element) {
return value != "-1"&&value!="";
});
$("#<%=btnReturn.ClientID %>").click(function () {
location.href = "LeXinCollectorManager.aspx";
});
var strCode = $("#<%=txtCollectorCode.ClientID%>").val();
$("#<%=hid_OriginalCode.ClientID %>").val(strCode);
$("form").first().validate
({
errorElement:"em",
rules:
{
<%=txtCollectorCode.UniqueID %>:{required:true,CheckCodeIsExists:true},
<%=ddlType.UniqueID%>:{CheckSelect:true}
},
messages:{
<%=txtCollectorCode.UniqueID %>:{required:'<%=Xys.Remp.Web.Resource.GetString("Remp_NotNull")%>',CheckCodeIsExists:'采集器序列号已存在'},
<%=ddlType.UniqueID%>:{CheckSelect:'请选择'}
},
errorPlacement:function(error,element){ error.appendTo(element.parent());}
});
});
</script>