如何使用clone复制数组

时间:2016-02-27 04:54:47

标签: arrays drop-down-menu textfield using

你能帮我解决一下这个错误吗,我的数组帖子没有用,它总是得到第一个值。它只复制文本字段。

我的内容使用下拉按钮复制字段的位置。

<h3>Step 3</h3>
            <label><strong>Shipment Details</strong></label><br>

                    <label>Quantity:</label>
                        <select class="form-control" id="num_item" name="items_ID[]">
                            <option value="0">- SELECT -</option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                            <option value="6">6</option>
                        </select><br>

            <div class="itemList">
                    <label>Package <span class="number">1</span> type *: </label>
                            <select class="form-control" name="packaging[]">
                                <option value="Letter Size"> Letter Size </option>
                                <option value="Small Box"> Small Box </option>
                                <option value="Meduim Box"> Meduim Box </option>
                                <option value="Large Box"> Large Box </option>
                                <option value="Tube"> Tube </option>
                                <option value="Pallet"> Pallet </option>
                            </select>
                            <br/>   

                    <label>Package Dimensions &amp; Weight: </label><br>
                            <input type="text" class="package-dimension form-control" name="pcklength[]" placeholder="Length *" style="width: 15%;" value=""/> 
                            <input type="text" class="package-dimension form-control" name="pckwidth[]" placeholder="Width *" style="width: 15%;" value=""/> 
                            <input type="text" class="package-dimension form-control" name="pckheight[]" placeholder="Height *" style="width: 15%;" value=""/> <strong>inch</strong> &nbsp;
                            <input type="text" class="package-dimension form-control" name="pckWeight[]" placeholder="Weight *" style="width: 35%;" value=""/> <strong>kg</strong> -->

                            <br><hr>
            </div>
            <div class="anotherItemList">

            </div>

我的剧本

//for required Item
//when the webpage has loaded do this
$(document).ready(function() {


        //if the value within the dropdown box has changed then run this code            
        $('#num_item').change(function(){
            //get the number of fields required from the dropdown box
            var num = $('#num_item').val();                  

            var i = 0;
            $(".newItemList").remove();
            if (num > 1){
                var i = 1;
                while (i < num){
                    $('.itemList').clone().appendTo('.anotherItemList').removeClass("itemList").addClass("newItemList newItemList-" + i);
                    $(".newItemList-" + i + " .number").text(i+1);
                    i++;
                }
            }
        });
    });

//end

0 个答案:

没有答案