凌寒飘香

____成风破浪会有时,直把云帆济沧海!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

<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>

posted on 2013-01-28 16:53  凌寒飘香  阅读(1917)  评论(0编辑  收藏  举报