0

我写了这个表格,它工作正常,除了应该复制地址值的复选框。不管我怎么写,改写,改正。它根本行不通。

代码的第一部分是表单,第二部分是代码的复制部分,第三部分是不相关的掩码。

$(document).ready(function () {
//Any hidden errors that were passed back from 4D?
// for signup forms, we need to see which form we will show the errors on
if ($("#referralForm1").is(":visible")){
    show4DErrors("#referralForm1"); 
}

$("#referralForm1").validate({
    rules: {
        Referral_Name_T: "required",
        Referral_Company_T: "required",
        Referral_Address_T: "required",
        Referral_City_T: "required",
        Referral_State_T: "required",

        Referral_Zip_T: {
            required: true,
            zipCode: true
        },

        Referral_PhoneFull_T: {
            required: true,
            phoneNumber: true
        },

        Referral_Email_T: {
            required: true,
            email: true,

        },
        Referral_EmailConfirm_T: {
            required: true,
            email: true,
            equalTo: "#Referral_Email_T"
        },

        Referral_PayToName_T: "required",
        Referral_PayToAddress_T: "required",
        Referral_PayToCity_T: "required",
        Referral_PayToState_T: "required",

        Referral_PayToZip_T: {
            required: true,
            zipCode: true
        },

    }
});


$("Referral_SameAsAbove_T").click(function(){ 
    if ($("Referral_SameAsAbove_T").is(':checked')) 
    { 
        // Checked, copy values 
        $("#Referral_PayToAddress_T").val($("#Referral_Address_T").val()); 
        $("#Referral_PayToCity_T").val($("#Referral_City_T").val()); 
        $("#Referral_PayToState_T").val($("#Referral_State_T").val()); 
        $("#Referral_PayToZip_T").val($("#Referral_Zip_T").val()); 
    } 
    else 
    { 
        // Clear on uncheck 
        $("#Referral_Address_T").val(""); 
        $("#Referral_City_T").val(""); 
        $("#Referral_State_T").val(""); 
    } 
}); 




//Mask Setup
$('#Referral_PhoneFull_T').mask('(999) 999-9999');
$('#Referral_Zip_T').mask('99999');
$('#Referral_PayToZip_T').mask('99999');

});

4

1 回答 1

3

看起来你的选择器是错误的

$("Referral_SameAsAbove_T")

If it is a class then supposed to be   $(".Referral_SameAsAbove_T") // prepended by a dot

If it is a id then supposed to be   $("#Referral_SameAsAbove_T") // prepended by a pound

编辑

处理文本框的更改事件..

$('input[type="text"]').on('change' , function() {
    if ($("Referral_SameAsAbove_T").is(':checked')) {
         if( this.id.indexOf('Address') > -1){
            $("#Referral_PayToAddress_T").val($(this).val());
         }

          if( this.id.indexOf('City') > -1){
            $("#Referral_PayToCity_T").val($(this).val());
         }
       // Other textbox conditions here

    }
    else{
        $(this).val('');
    }

});

小提琴

注意:这只是为了处理 PayToAddress_T 文本框的更改事件。为他人

于 2012-10-02T17:39:36.017 回答