jQuery show / hide不支持克隆的元素集

时间:2012-11-15 17:08:33

标签: jquery show-hide html-select

以下是我的脚本。 .OtherCheck部分是不起作用的。当我添加(克隆)元素集时,它就像.OtherCheck部分没有看到新的元素集或其他东西..如果这是问题,如何使检查始终保持一致?

 $(document).ready(function(){

    $("#RMAForm").validate({
        errorPlacement: function(error,element) {
            return true;
        }
    });

    $("#InvoiceDate").datepicker();

    var textarea = $('.OtherText');
    var textlabel = $('.OtherLabel');
    textarea.hide();
    textlabel.hide();

    $('.OtherCheck').change(function(){
            var selectL = $(this).val();
            if (selectL == 'Other'){
              textlabel.show();
              textarea.show();
            }
            else {
              textlabel.hide();
              textarea.hide();
            }
    });

    var i = 2;

    $("#AddOne").click(function () {
        if (i < 11) {
            var itemNum = "<div class='iSep'>Item "+ i +"</div>";
            $(".cloneSet:first").clone().prepend(itemNum).appendTo("#cloneRet").children(":not(div):not(br)").each(function(){
            $(this).val("");
            var nameAttr = $(this).attr("name") + i;
            var forAttr = $(this).attr("for") +i;
            $(this).not("label").attr("name", nameAttr);
            $(this).not("select").not("textarea").attr("for", forAttr);
            });
            i++;
        }
    });

    $("#RemoveOne").click(function(){
        if (i >= 3 && i <= 11) {
        $(".cloneSet:last").remove();   
        i--;            
        }
    });

  });





<div id="RMAMain">
<form method="POST" action="contact.asp" id="RMAForm">
<div id="mainContent">
<label for="EmailFrom"><span style="color: #F00;">*</span>Your Email:</label>
<input type="text" name="EmailFrom" class="required"><br />
<label for="DealerName">Dealer Name:</label>
<input type="text" name="DealerName"><br />
<label for="DealerNumber">Dealer Number:</label>
<input type="text" name="DealerNumber"><br />
<label for="InvoiceNumber"><span style="color: #F00;">*</span>Invoice Number:</label>
<input type="text" name="InvoiceNumber" class="required"><br />
<label for="PONumber">PO Number:</label>
<input type="text" name="PONumber"><br />
<label for="InvoiceDate"><span style="color: #F00;">*</span>Invoice Date:</label>
<input type="text" name="InvoiceDate" class="required" id="InvoiceDate"><br />
</div>
<div id="sideContent">
<div class="iSep">Item 1</div>
<div class="cloneSet">
<label for="ModelNumber"><span style="color: #F00;">*</span>Model Number:</label>
<input type="text" name="ModelNumber" class="required"><br />
<label for="SerialNumber">Serial Number:</label>
<input type="text" name="SerialNumber"><br />
<label for="ConditionofUnit"><span style="color: #F00;">*</span>Condition:</label>
<select name="ConditionofUnit" class="required">
<option value="">Choose an option</option> 
<option value="Open: Defective">Open: Defective</option>
<option value="Open: Non-defective">Open: Non-defective</option>
<option value="Factory Sealed">Factory Sealed</option>
</select><br />
<label for="ReasonforRMA"><span style="color: #F00;">*</span>Reason for RMA:</label>
<select name="ReasonforRMA" class="required OtherCheck">
<option value="">Choose an option</option> 
<option value="Wrong Item">Wrong Item</option>
<option value="Defective">Defective</option>
<option value="Unit Damaged">Unit Damaged</option>
<option value="Other">Other</option>
</select><br />
<label for="OtherText" class="OtherLabel">Other Reason:</label>
<textarea name="OtherText" class="OtherText"></textarea><br />
</div>
<div id="cloneRet"></div>
<div class="iSepT"><a href="#" id="AddOne"><button class="AddRem">Add Another Item</button></a><a href="#" id="RemoveOne"><button class="AddRem">Remove Last Item</button></a><button class="submit" type="submit" name="RMASubmit">Submit RMA Request</button></div>
</div>
</form>
</div>

0 个答案:

没有答案