如何在不传输值的情况下克隆字段集

时间:2013-04-11 14:51:58

标签: javascript jquery hidden-field cloning

我正试图克隆一个没有克隆输入而选择的字段集。 (我需要空白)。我在表单的主体中创建了一个隐藏的字段集,但不是表单本身,但我似乎无法让它工作

 <div id="analyte" style="display: none">
 <div class="_40">
 <label class="analyte-label" for="analyte">Analyte:</label>
    <input class="analyte" type="text" id="analyte1" name="analyte" value=""> </div>
 <div class="_30">
     <label class="preserved-label" for="preserved">Preserved</label>
 <select class="select_preserved" id="preserved1" name="preserved" data-iconpos="left" data-icon="grid" data-native-menu="false" >
        <option value = ""></option>
           <option value = "HNO3">HNO&#8323;</sub></option>
           <option value = "H2SO4">H&#8322;SO&#8324;</option>
           <option value = "H3PO4">H&#8323;PO&#8324;</option>
           <option value = "HCL">HCL</option>
           <option value = "None1">None</option>
    </select></div></div>

然后我以

的形式使用此代码
 <input type="button" id="add_Analyte" onclick="add_Analyte" value="ADD ANALYTE" /></div>
<script>
$(document).ready(function() {
var _counter = 0;
function add_Analyte() {
_counter++;
var newFields = document.getElementById("Analyte").cloneNode(true);
newFields.id = "";
newFields.style.display = "block";
var newField = newFields.childNodes;
for (var i=0;i<newField.length;i++) {
var theName = newField[i].name
    if (theName)
        newField[i].name = theName + counter;
}
var insertHere = document.getElementById("addAnalyte");
insertHere.parentNode.insertBefore(newFields,insertHere);
}
})
</script> 

0 个答案:

没有答案