1

我想像这样传递文件的名称属性...

rules: {               
             '($(txtFName).attr('name'))': {
             required: true,
             No_Spl_Char: "DFT"
             }
    },

这不起作用,我似乎找不到任何其他方法来传递名称属性。我也使用 UniqueID 来获取名称属性,但表单字段位于不同的控件中,因此它不起作用。任何人都可以提出更聪明的方法来获取名称属性并通过。帮助总是受到赞赏。

我有多个规则和消息......我不能再使用 UniqueID,因为一些文件在不同的控件中而不是在同一个控件中。

$(document).ready(function() {
    // validate the comment form when it is submitted
    $("#aspnetForm").validate({
    onfocusout: function(element) { $(element).valid(); },
    success: function(label) {
       label.addClass("validfld");
    },
    validClass: "validfld",  
    rules: {
            <%=txtFNameRoom.UniqueID%>: {
             required: true,
             No_Spl_Char: true
             },
             <%=txtLNameRoom.UniqueID%>: {
             required: true,
             No_Spl_Char: true
             },
             <%=txtEmail.UniqueID%>: {
             required: true,
             email: true
             },
             <%=ddlCountry.UniqueID%>: {
             required: true,
             valueNotEquals: "DFT"
             },
             <%=ddlMobileNumber.UniqueID%>: {
             required: true,
             valueNotEquals: "DFT"
             },
             <%=txtTelephone.UniqueID%>: {
             required: true,
             digits: true
             },
             <%=DropDownList1.UniqueID%>: {
             required: true,
             valueNotEquals: "DFT"
             }
    },
    messages: {
        <%=txtFNameRoom.UniqueID%>:{
            required: "Please enter your firstname.",
            No_Spl_Char: "Special Characters are not allowed."
        },
        <%=txtLNameRoom.UniqueID%>:{
            required: "Please enter your lastname.",
            No_Spl_Char: "Special Characters are not allowed."
        },
        <%=txtEmail.UniqueID%>:{
        required: "Please enter your email.",
        email: "Please enter valid email."
        },
        <%=ddlCountry.UniqueID%>:{
        required: "Please select your country.",
        valueNotEquals: "Please select your country."
        },
        <%=ddlMobileNumber.UniqueID%>: "Please enter your country code.",
        <%=txtTelephone.UniqueID%>:{
        required: "Please enter your email.",
        digits: "Please enter only digits."
        },
        <%=DropDownList1.UniqueID%>: "Please select your bed preference."

}
4

1 回答 1

0

你可以试试这个:

var rulesObject = {};
rulesObject[$(txtFName).attr('name')] = {
   required: true,
   No_Spl_Char: "DFT"
};
rulesObject['<%=txtFNameRoom.UniqueID%>'] = {
    required: true,
    No_Spl_Char: true
};
rulesObject['<%=ddlCountry.UniqueID%>'] = {
    required: true,
    valueNotEquals: "DFT"
};
//etc...


//then

$("#aspnetForm").validate({
     //......
     rules: rulesObject
     //......
于 2012-07-27T07:48:40.007 回答